//函数调用运算符重载:
//1、operator()
//2、因为使用方式很像函数调用,所以也称之为伪函数
//3、没有固定写法,很灵活
#include<iostream>
using namespace std;
class Print {
public:
void operator()(string test) {
cout << test << endl;
}
};
class MyAdd {
public:
int operator()(int a, int b) {
return a + b;
}
};
void test01() {
Print print;
print("测试案例");
}
void test02() {
MyAdd myadd;
int ret = myadd(10, 20);
cout << "ret=" << ret << endl;
//匿名函数对象,MyAdd()表示匿名对象,后面的括号是运算符重载
cout << MyAdd()(10, 30) << endl;
}
int main() {
test01();
test02();
return 0;
}