错误:[类内的typedef]没有命名类型

liv2hak

我实现了一个类buffer_manger。头文件(.hpp)和(.cpp)文件在下面给出。

buffer_manager.hpp

#ifndef BUFFER_MANAGER_H                                                                                                                                                                                           
#define BUFFER_MANAGER_H

#include <iostream>
#include <exception>
#include <boost/array.hpp>
#include <boost/algorithm/hex.hpp>
#include <algorithm>
#include <iomanip>


class buffer_manager
{
public:
    typedef boost::array<unsigned char, 4096> m_array_type;
    m_array_type recv_buf;
    buffer_manager();
    ~buffer_manager();
    std::string message_buffer(m_array_type &recv_buf);
    m_array_type get_recieve_array();

private:
  std::string message;
};

#endif //BUFFER_MANAGER_H

buffer_manager.cpp

#include <iostream>                                                                                                                                                                                                
#include <boost/array.hpp>
#include <boost/algorithm/hex.hpp>
#include <algorithm>
#include "buffer_manager.hpp"


buffer_manager::buffer_manager()
{

}
buffer_manager::~buffer_manager()
{

}
std::string buffer_manager::message_buffer(m_array_type &recv_buf)
{
    boost::algorithm::hex(recv_buf.begin(), recv_buf.end(), back_inserter(message));
    return message;
}

m_array_type buffer_manager::get_recieve_buffer()
{
  return recv_buf;
}

问题是我在类buffer_manager中定义了一个类型m_array_type。我还声明了一个名为该类型的变量recv_buf

我试图为该成员变量实现访问器函数。我得到的错误

buffer_manager.cpp:22:1: error: ‘m_array_type’ does not name a type
 m_array_type buffer_manager::get_recieve_buffer()

如何获取buffer_manager.cpp来识别类型 m_array_type

巴里

您只需要限定它:

buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
^^^^^^^^^^^^^^^^
{
    return recv_buf;
}

成员函数名称之后的所有内容都将在类的上下文中查找,但不会在返回类型中查找。

作为旁注,您是否真的要按值返回它?也许m_array_type&吧?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章