boost之function

boost中function是对函数指针和函数对象的进行封装的模板类。

定义示例:function<int()> func生成一个空的对象,表示函数参数个数为零,返回类型为int。

#include <iostream>
#include <string>
#include <vector>
#include <boost/function.hpp>
using namespace std;
using namespace boost;

int f(int a,int b)
{
	return a + b;
}


int main()
{
	function<int(int,int)> fun;//定义一个空的function对象
	fun = f;//调用赋值操作符
	if (fun)
	{
		cout << fun(10,20) <<endl;
	}
	fun.empty(); //清空
	return 0;
}
原文地址:https://www.cnblogs.com/liuweilinlin/p/3255134.html