Tutorial :Using boost memory pool in class


I tried to declare a memory pool in my class.

But the compiler shows some basic error like missing ')' before ';'

or syntax error : 'sizeof'

It works well if I used the pool as local variable but I really want to make it live with the class.

What's wrong about my usage?

Here is the class, the MAX_OBJ is a const

  class CData  {  public:   CData(void);   ~CData(void);  private:   boost::pool m_Pool(sizeof(DWORD) * MAX_OBJ);  };  


I don't think it as anything to do with boost::pool.

But this line:

boost::pool m_Pool(sizeof(DWORD) * MAX_OBJ);  

Should probably be:

boost::pool m_Pool;  

And your constructor should then be:

CData::CData() :    m_Pool(sizeof(DWORD) * MAX_OBJ)  {  }  

You cannot construct members in the class declaration. You can just say: "My class has a member named m_Pool whose type is boost::pool."

You then specify in one or several constructor(s), how this member is initialized.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »