c++ - 错误 : [typedef inside a class] does not name a type

标签 c++ c++11 boost

我已经实现了一个类buffer_manger。头文件(.hpp)和(.cpp)文件如下。

缓冲区管理器.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

缓冲区管理器.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&

关于c++ - 错误 : [typedef inside a class] does not name a type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35541929/

相关文章:

c++ - 这是通用引用吗? std::forward 在这里有意义吗?

c++ - 如何从文本文件中获取长度为 9 的单词?

c++ - boost::lockfree 中的 "wait-free"到底是什么意思?

c++ - 柠檬在 C++ 中生成的解析器的段错误

c++ - 允许在单链表 C++ 的合并排序中重复

c++ - 使用套接字一次发送整个数据

c++ - 如何引用随机生成器?

c++ - boost 信号和传递类方法

c++ - 当ini文件不存在时使用Boost属性树读取INI文件

c++ - 类方法内部链接