Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: [typedef inside a class] does not name a type

Tags:

c++

c++11

boost

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

like image 778
liv2hak Avatar asked May 16 '26 01:05

liv2hak


2 Answers

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&?

like image 159
Barry Avatar answered May 17 '26 14:05

Barry


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()
like image 34
Pete Becker Avatar answered May 17 '26 16:05

Pete Becker