struct write_five_obj
{
void operator()() const
{
global_int = 5;
}
};
static void write_five()
{
global_int = 5;
}
//赋值的类型2种:
typedef function<void()> func_void_type;
write_five_obj five;
func_void_type v1;
v1 = five;
v1 = write_five;
//可交换
swap(v1, v2);
//成员函数
struct X
{
X(int v) : value(v) {}
int twice() const { return 2 * value; }
int plus(int v) { return value + v;}
int value;
};
static void test_member_functions()
{
boost::function<int (X*)> f1(&X::twice);
X one(1);
X five(5);
std::cout << f1(&one) << " " << f1(&five) << std::endl;
}