【发布时间】:2011-11-17 16:35:22
【问题描述】:
信息
我想使用 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);
问题
我刚刚在 Debug 中编译了解决方案,一切看起来 OK ...
但是在Release中我遇到了很多上面提到的错误
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 不支持某些东西(我不知道具体是什么)
我说的对吗?
我还需要使这个应用程序尽可能便携和跨平台。
提升 1.47 和 VS2010
【问题讨论】:
-
MSVC10 不支持可变参数模板。任何伪造可变参数行为(例如
bind)的东西都必须在幕后使用一些肮脏的诡计。 -
@kerrekSB 所以......如果我想使用传递回调函数作为参数的方法,我应该怎么做。就像在 ASIO 中所做的那样。
-
不知道,抱歉 :-) 听起来这是 MSVC 特有的问题。我相信有该编译器经验的人很快就会发布一些有用的东西!
标签: c++ visual-studio-2010 boost boost-function