函数调用运算符重载
#include <iostream>
class Add
{
public:
int operator()(int a, int b)
{
std::cout << "operator()" << std::endl;
return a + b;
}
};
int main()
{
using namespace std;
Add add;
int ret = add(10, 20);
cout << ret << endl;
/* 匿名对象 */
cout << Add()(10, 20) << endl;
return 0;
}
operator()
30
operator()
30