64,642
社区成员
发帖
与我相关
我的任务
分享
#include <functional>
#include <vector>
typedef std::function<int()> fp;
typedef std::vector<fp> VE_FUNC;
//待绑定函数
int tests()
{
printf("tests\n");
return 0;
}
int tests1(int a)
{
printf("tests1:%d\n",a);
return 1;
}
int tests2(int a,float aa)
{
printf("tests2:%d,%f\n",a,aa);
return 2;
}
int tests3(int a,float aa,char* p)
{
printf("tests3:%d,%f,%s\n",a,aa,p);
return 3;
}
//绑定
VE_FUNC ve_func;
fp f = std::bind(tests);
ve_func.push_back(f);
f = std::bind(tests1,12);
ve_func.push_back(f);
f = std::bind(tests2,12,11.11);
ve_func.push_back(f);
f = std::bind(tests3,13,11.22,(char*)"1233477");
ve_func.push_back(f);
//调用
for(int i=0;i < ve_func.size(); i++)
{
ret = (ve_func[i])();
printf("ret:%d\n",ret);
}
enum E_FUN_TYPE
{
e_FT_One,
e_FT_Two,
e_FT_Three
};
int tests(int a,float aa,char* p, E_FUN_TYPE eType)
{
int nResult = -1;
switch ( eTyp )
{
}
return nResult;
}