在课堂上使用boost内存池
我试图在我的班级中声明一个内存池。
但编译器显示一些基本错误,例如在 ';' 之前缺少 ')'
或语法错误:'sizeof'
如果我使用池作为局部变量,它会很好地工作,但我真的想让它与类一起存在。
我的使用有什么问题吗?
这是类,MAX_OBJ 是一个 const
class CData
{
public:
CData(void);
~CData(void);
private:
boost::pool m_Pool(sizeof(DWORD) * MAX_OBJ);
};
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);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与 boost::pool 没有任何关系。
但这行:
可能应该是:
然后你的构造函数应该是:
你不能在类声明中构造成员。您可以直接说:“我的类有一个名为
m_Pool
的成员,其类型为boost::pool
”。然后,您可以在一个或多个构造函数中指定如何初始化该成员。
I don't think it as anything to do with
boost::pool
.But this line:
Should probably be:
And your constructor should then be:
You cannot construct members in the class declaration. You can just say: "My class has a member named
m_Pool
whose type isboost::pool
."You then specify in one or several constructor(s), how this member is initialized.