#include <iostream>
#include <string>
using namespace std;
/*
函数调用运算符重载
*/
class Person
{
public:
// 重载函数调用运算符 重载了小括号 也叫作访函数 没有固定的写法
void operator()(string test)
{
cout << test << endl;
}
// 这个也是防函数
int operator()(int num1, int num2)
{
return num1 + num2;
}
};
void test()
{
Person p;
p("lcs");
}
void test1()
{
Person p;
p(20, 30);
cout << p(20, 30) << endl;
// 匿名对象 Person() 当前行执行完毕 匿名对象会被立即释放
cout << Person()(20, 20) << endl;
}
int main()
{
test1();
return 0;
}