c++ ()括號操作符的過載
阿新 • • 發佈:2019-02-10
- #include <iostream>
- usingnamespace std;
- class Clastype
- {
- public:
- Clastype(int a)
- {
- cout << "Hello Clastype!" << a << endl;
- }
- bool operator ()(int b)
- {
-
cout << "Hello Clastype()!" << b << endl;
- returntrue;
- }
- };
- int main()
- {
- Clastype a(1);
- Clastype(2);
- Clastype t = Clastype(3);
- t(4);
- Clastype *b = new Clastype(5);
- (*b)(6);
- }
- @-desktop:~/test$ g++ -o o 6.cpp
- @-desktop:~/test$ ./o
- Hello Clastype!1
- Hello Clastype!2
-
Hello Clastype!3
- Hello Clastype()!4
- Hello Clastype!5
- Hello Clastype()!6