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
| #include<iostream> using namespace std;
class MyPrint { public: void operator()(string test) { cout << test << endl; } };
class MyAdd { public: int operator()(int a, int b) { return a + b; } }; void test01() { MyPrint Myprint; Myprint("hello world"); MyAdd Myadd; cout << "Myadd(100, 100) = " << Myadd(100, 100) << endl; cout << "Myadd()(100, 100) = " << MyAdd()(100, 100) << endl; } int main() { test01(); return 0; }
|