重载小括号也被称为仿函数
#include<iostream>
using namespace std;
class MyPrint
{
public:
void operator()(string test)
{
cout<<test<<endl;
}
};
class MyAdd
{
public:
int operator()(int num1,int num2)
{
return num1+num2;
}
};
void test01()
{
MyPrint myprint;
myprint("hello world");
}
void test02()
{
MyAdd myadd;
int res= myadd(100,100);
cout<<"res="<<res<<endl;
//MyAdd()(100,100)是匿名对象
cout<<MyAdd()(100,100)<<endl;
}
int main()
{
//test01();
test02();
}