Reputation: 15010
I have implemented a class buffer_manger.The header file (.hpp) and (.cpp) files are given below.
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;
}
The problem is I have defined a type m_array_type insde the class buffer_manager. I have also declared a variable of that type named recv_buf
I tried to implement an accessor function for that member variable. I get the error that
buffer_manager.cpp:22:1: error: ‘m_array_type’ does not name a type
m_array_type buffer_manager::get_recieve_buffer()
How do I get the buffer_manager.cpp to recognize the type m_array_type
Upvotes: 2
Views: 2861
Reputation: 76523
m_array_type buffer_manager::get_recieve_buffer()
The problem here is that when the compiler sees m_array_type
it doesn't know that it's compiling a member function. So you have to tell it where that type is defined:
buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
Upvotes: 4
Reputation: 304142
You simply need to qualify it:
buffer_manager::m_array_type buffer_manager::get_recieve_buffer()
^^^^^^^^^^^^^^^^
{
return recv_buf;
}
Everything after the member function name will get looked up in the context of the class, but not the return type.
As a side-note, do you really want to return it by-value? Perhaps m_array_type&
?
Upvotes: 9