错误: [类中的 typedef] 未命名类型
error: [typedef inside a class] does not name a type
我已经实现了一个类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;
}
问题是我已经定义了一个类型m_array_type 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()
如何让buffer_manager.cpp识别类型m_array_type
你只需要限定它:
buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
^^^^^^^^^^^^^^^^
{
return recv_buf;
}
成员函数名称之后的所有内容都将在类的上下文中查找,但不会在返回类型中查找。
作为旁注,您真的要按值返回它吗?也许m_array_type&
?
m_array_type buffer_manager::get_recieve_buffer()
这里的问题是,当编译器看到m_array_type
时,它不知道它正在编译成员函数。所以你必须告诉它该类型在哪里定义:
buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
相关文章:
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 为什么未命名的结构内联变量在每个翻译单元中没有相同的地址?
- C++中未命名函数指针的语法
- 未命名的非类型模板参数有什么意义?
- C++包含函数标头会给出错误'__dest'未命名类型
- 不同C++文件中未命名命名空间中的名称可以引用同一个命名事物吗?
- 用于创建未命名实例的语法
- 错误:"cast"未命名类型void setCastDescription(std::string
- 我可以定义一个 constexpr 匿名/未命名变量吗?
- C++ 错误:(类名)未命名类型
- 如何访问嵌套在命名命名空间中的未命名命名空间变量?
- 未命名的函数参数用法
- 使用 std ::transform 构造 std::vector.返回未命名结果的可能性?
- 为什么将字符串输出到未命名的 std::ofstream 反而给了我一个十六进制数?
- 在多个 cpp 文件中重用未命名的命名空间函数
- C++ ,错误:命名空间'std'中的'shared_ptr'未命名模板类型
- src/caffe/parallel.cpp:70:1:错误:“参数”未命名类型
- 错误: [类中的 typedef] 未命名类型
- 向前声明未命名结构的 typedef
- typedef声明定义未命名类时链接失败