#include<iostream>#include<functional>void func(void){ std::cout << __FUNCTION__ << std::endl;}void callback(std::function<int(int,char*)> fr){ fr(1,"gdg");}int strlength(int n,constchar* str){return n + strlen(str);}void outPut(int x,int y){ std::cout << x <<" "<< y << std::endl;}int main(){//测试bind auto fr = std::bind(strlength, std::placeholders::_1, std::placeholders::_2);//function作为函数参数 callback(fr); std::bind(strlength,1,"hhha")(); std::bind(strlength, std::placeholders::_1,"hha")(45);//第一个参数从外面传入,第二个参数已经设置好了 std::bind(strlength,23, std::placeholders::_1)("lallaa");//bind里按照函数的参数顺序来 std::bind(strlength, std::placeholders::_2, std::placeholders::_1)("hhafdsf",25);//第一个参数用传入的第二个参数,第二参数用传入的第一个参数 std::bind(strlength, std::placeholders::_1, std::placeholders::_3)(12,45,"fhsafdf");//对,第二个参数没用到}原文:http://www.cnblogs.com/dongdongweiwu/p/4743656.html