Halaman

Rabu, 28 Maret 2012

c++: Boost "Bind" and "Functions" snippet

This is a personal note on using the boost library, since i come from a Delphi background, been trying to figure out the callback method which is simple to use in c++.. and then i come across useful boost library functions.. well the code should tell you more.. so here is the snippet :
//Using bind with Boost.Function
class button
{
public:

    boost::function onClick;
};

class player
{
public:

    void play();
    void stop();
};

button playButton, stopButton;
player thePlayer;

void connect()
{
    playButton.onClick = boost::bind(&player::play, &thePlayer);
    stopButton.onClick = boost::bind(&player::stop, &thePlayer);
}

pretty neat doesn't it? :)

Tidak ada komentar:

Posting Komentar