// Test_boost_bind_function.cpp: defines the entry point for the console application. <br/> // <br/> # include "stdafx. H "<br/> # include <boost/mem_fn.hpp> <br/> # include <boost/Ref. HPP> <br/> # include <boost/type. HPP> <br/> # include <boost/bind. HPP> <br/> # include <boost/function. HPP> <br/> # include <iostream> <br/> class button <br/>{< br/> Public: <br/> boost :: function <void ()> onclick; <br/>}; <br/> class Player <br/>{< br/> Public: <br/> void play () {STD: cout <"play! /N ";}< br/> void stop () {STD: cout <" Stop! /N ";}< br/>}; <br/> button playbutton, stopbutton; <br/> player theplayer; <br/> void connect () <br/>{< br/> playbutton. onclick = boost: BIND (& PLAYER: Play, & theplayer); <br/> stopbutton. onclick = boost: BIND (& PLAYER: Stop, & theplayer); <br/>}< br/> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> connect (); <br/> playbutton. onclick (); <br/> stopbutton. onclick (); <br/> return 0; <br/>}< br/>
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