VS2010 中的 boost::function : 错误 C2039: 'function' : 不是“boost”的成员;
信息
我想使用 boost::function 将回调作为参数传递,就像这样:
void ReadPacket(
boost::function<void (const boost::system::error_code&, Packet* p)> callback);
然后使用它:
ReadPacket(boost::bind(
&ServerSession::storePacket,
this,
_1,
_2
));
毕竟在一系列回调之后我调用了
callback(ec, packet);
问题
我刚刚在调试 一切看起来都OK ...
但是在发布中我遇到了上面提到的很多错误,
BasicSession.h(30): error C2039: 'function' : is not a member of 'boost'
BasicSession.h(30): error C2061: syntax error : identifier 'function'
BasicSession.h(30): error C2059: syntax error : ')'
BasicSession.h(30): error C2143: syntax error : missing ')' before ';'
我感到困惑和失望。
建议
我发现 boost::function
中有不同的语法。例如 boost::function0
或 boost::function1
。这是因为 VS2010 不支持某些东西(我不知道到底是什么),
我对吗?
我还需要使这个应用程序尽可能地可移植和跨平台。
Boost 1.47 和 VS2010
INFO
I'd like to use boost::function to pass callback as parameter, like this way:
void ReadPacket(
boost::function<void (const boost::system::error_code&, Packet* p)> callback);
and then use it :
ReadPacket(boost::bind(
&ServerSession::storePacket,
this,
_1,
_2
));
After all after a chain of callbacks i call
callback(ec, packet);
PROBLEM
I've just compiled solution in Debug and everything looks OK ...
but in Release I got lots of errors mentioned above
BasicSession.h(30): error C2039: 'function' : is not a member of 'boost'
BasicSession.h(30): error C2061: syntax error : identifier 'function'
BasicSession.h(30): error C2059: syntax error : ')'
BasicSession.h(30): error C2143: syntax error : missing ')' before ';'
I'm confused and dissappointed.
SUGGESTION
I've found that there're different syntax in boost::function
. For example boost::function0
or boost::function1
. This was made due to VS2010 doesn't support something (I don't know what exactly)
Am I right?
I also need to make this application as portable and cross-platform as possible.
boost 1.47 and VS2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您错过了,这里是教程< /a> 开启升压功能。如果您查看教程,它将列出“首选”和“可移植”语法。由于您希望代码可移植,因此您可能需要选择后者。
In case if you have missed it, here is the tutorial on boost function. If you look at the tutorial it will list both the 'preferred' and the 'portable' syntax. Since you want the code to be portable, you might want to choose the latter.
解决方案是
boost::function4
the solution is
boost::function4