1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream> using namespace std;
class MyPrint { public:
void operator()(string text) { cout << text << endl; } };
class MyAdd { public: int operator()(int a,int b) { return a + b; } };
void test01() { MyPrint myPrint; myPrint("Hello World"); }
void test02() { MyAdd add; int ret = add(10, 20); cout << ret << endl;
cout << MyAdd()(100, 200) << endl; }
int main(){ test01(); test02(); return 0; }
|