您的位置:首页 > 其它

Boost Bind 类成员函数指针

2010-08-21 15:38 501 查看
// Test_BOOST_BIND_FUNCTION.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <boost/mem_fn.hpp>
#include <boost/ref.hpp>
#include <boost/type.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
class button
{
public:
boost::function<void()> onClick;
};
class player
{
public:
void play(){std::cout<<"Play!/n";}
void stop(){std::cout<<"Stop!/n";}
};
button playButton, stopButton;
player thePlayer;
void connect()
{
playButton.onClick = boost::bind(&player::play, &thePlayer);
stopButton.onClick = boost::bind(&player::stop, &thePlayer);
}
int _tmain(int argc, _TCHAR* argv[])
{
connect();
playButton.onClick();
stopButton.onClick();
return 0;
}


Reference:

http://www.boost.org/doc/libs/1_44_0/libs/bind/bind.html

http://msdn.microsoft.com/en-us/library/bb982702(v=VS.90).aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: