2

信息

我想使用 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中编译了解决方案,一切看起来都很好......

但是在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::function0boost::function1。这是因为 VS2010 不支持某些东西(我不知道到底是什么)

我对吗?

我还需要使这个应用程序尽可能可移植和跨平台。

提升 1.47 和 VS2010

4

2 回答 2

3

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.

于 2011-11-17T16:42:32.877 回答
2

the solution is boost::function4

于 2011-11-17T16:40:53.237 回答