函数运算符重载
约 0 个字 32 行代码 预计阅读时间不到 1 分钟
#include <iostream>
#include <string>
using namespace std;
class MyPrint{
public:
void operator()(string text){
cout << text << endl;
}
};
class MyAdd{
public:
int operator()(int v1,int v2){
return v1 + v2;
}
};
void test1(){
MyPrint myPrint;
myPrint("hello world");
MyAdd myAdd;
int res = myAdd(10,10);
cout << res << endl;
}
int main(){
test1();
return 0;
}