函数对戏就是重载了()运算符的类的对象,它可以像1个函数1样使用。
-
#include <iostream>
-
#include<functional>
-
using namespace std;
-
-
-
-
class MyAdd{
-
public:
-
int operator()(int a,int b){
-
return a+b;
-
}
-
};
-
class MyMinus{
-
public:
-
int operator()(int a,int b){
-
return a-b;
-
}
-
};
-
int main(int argc, _TCHAR* argv[]){
-
int a=1;
-
int b=2;
-
MyAdd addobj;
-
MyMinus minusobj;
-
cout<<"a+b="<<addobj(a,b)<<endl;
-
cout<<"a-b="<<minusobj(a,b)<<endl;
-
minus<int> int_minus;
-
cout<<int_minus(7,9)<<endl;
-
getchar();
-
return 0;
-
}