std::function是一种C++11的新特性。是可调用对象的包装器,是一个类模板,它可以统一处理函数,函数对象,函数指针,并允许保存和延迟执行它们。std::function<A(B)> func;其中A表示接受函数的返回值,B表示参数,那么依次推测如下代码中哪几行添加是对的?
#include <iostream>
#include <functional>
#include <string>
#include <vector>
typedef std::function<int(int, std::string)> testFuncCallback;
void func1(int a, std::string b)
{
}
int func2(int a, std::string b)
{
return 0;
}
int func3(std::string a, int b)
{
return 0;
}
int func4(int a, int b, std::string c)
{
return 0;
}
std::string func5(int a, int b)
{
return "";
}
int main(void)
{
std::vector<testFuncCallback> testFuncCallbackVec;
testFuncCallbackVec.push_back(func1);//1
testFuncCallbackVec.push_back(func2);//2
testFuncCallbackVec.push_back(func3);//3
testFuncCallbackVec.push_back(func4);//4
testFuncCallbackVec.push_back(func5);//5
return 0;
}