小编cod*_*ing的帖子

如何使用boost :: bind绑定类成员函数?

#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();
}
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-bind boost-function c++11

6
推荐指数
1
解决办法
3589
查看次数

标签 统计

boost ×1

boost-bind ×1

boost-function ×1

c++ ×1

c++11 ×1