1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
struct foo {
void my_callback( int x, int y ) const
{ std::cout << __PRETTY_FUNCTION__ << " called, x = " << x << " and y = " << y << std::endl; }
}
struct bar {
void my_callback( int x, int y, int z ) const
{ std::cout << __PRETTY_FUNCTION__ << " called, x = " << x << " y = " << y << " and z = " << z << std::endl; }
};
int main() {
foo f;
bar b;
boost::function<void( int, int )> f_callback = boost::bind( &foo::my_callback, &f, _1, _2 );
boost::function<void( int, int )> b_callback = boost::bind( &bar::my_callback, &b, _1, _2, 42 );
f_callback( 2, 3 );
b_callback( 3, 4 );
}
|