#include <QtCore/QCoreApplication>
#include <boost/bind.hpp>
#include <boost/function.hpp>
class button
{
public:
boost::function<void()> onClick;
boost::function<void(int ,double )> onClick2;
};
class player
{
public:
void play(int i,double o){}
void stop(){}
};
button playButton, stopButton;
player thePlayer;
void connect()
{
//error C2298: 'return' : illegal operation on pointer to member function expression
playButton.onClick2 = boost::bind(&player::play, &thePlayer);
stopButton.onClick = boost::bind(&player::stop, &thePlayer);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
connect();
return a.exec();
}
问问题
3748 次
2 回答
13
boost::bind(&player::play, &thePlayer)
您需要为两个参数使用占位符:
boost::bind(&player::play, &thePlayer, _1, _2)
占位符允许您说“我只绑定某些参数;其他参数将在稍后提供。”
于 2011-02-08T04:29:46.363 回答
2
如果您想创建可移植代码 - 直接指定占位符的命名空间:
boost::bind( &player::play, &thePlayer, ::_1, ::_2 ); // Placeholders of boost::bind are placed in global namespace.
于 2011-02-16T18:19:05.347 回答