#include <iostream>
#include <future>
#include <vector>
#include <map>
#include <functional>
#include <string>
using namespace std;
int echovalue(int v)
{
cout << "int echovalue(int v) :"<< v << endl;
return v;
}
class biggerthenzero
{
public:
int operator() (int v)
{
cout << "int operator() ():"<< v << endl;
return v;
}
};
int main()
{
map<string, int(*)(int)> myoper;
myoper.insert({"ev",echovalue});
biggerthenzero obj;
function<int(int)> f1 = echovalue;
function<int(int)> f2 = obj;
function<int(int)> f3 = biggerthenzero();
f1(5);
f2(3);
f3(0);
map<string, function<int(int)>> myoper1 =
{
{"ev",echovalue},
{"bt",obj},
{"bt2",biggerthenzero()},
};
myoper1["ev"](12);
myoper1["bt"](12);
myoper1["bt2"](12);
return 0;
}
C++ function 类模板
最新推荐文章于 2024-08-04 15:38:02 发布