在课堂上使用boost内存池

发布于 2024-09-13 07:03:59 字数 315 浏览 4 评论 0原文

我试图在我的班级中声明一个内存池。

但编译器显示一些基本错误,例如在 ';' 之前缺少 ')'

或语法错误:'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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-09-20 07:03:59

我认为这与 boost::pool 没有任何关系。

但这行:

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

可能应该是:

boost::pool m_Pool;

然后你的构造函数应该是:

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

你不能在类声明中构造成员。您可以直接说:“我的类有一个名为 m_Pool 的成员,其类型为 boost::pool”。

然后,您可以在一个或多个构造函数中指定如何初始化该成员。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文