我已经实现了一个类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
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
问题是我已经定义了一个类型m_array_type insde类buffer_manager.我还声明了一个名为的那个类型的变量recv_buf
我试图为该成员变量实现一个访问器函数.我得到了错误
buffer_manager.cpp:22:1: error: ‘m_array_type’ does not name a type
m_array_type buffer_manager::get_recieve_buffer()
Run Code Online (Sandbox Code Playgroud)
如何让buffer_manager.cpp识别该类型 m_array_type
您只需要对其进行限定:
buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
^^^^^^^^^^^^^^^^
{
return recv_buf;
}
Run Code Online (Sandbox Code Playgroud)
成员函数名之后的所有内容都将在类的上下文中查找,但不会返回返回类型.
作为旁注,你真的想要按价值归还吗?也许m_array_type&吧?