#include<iostream>
using namespace std;
class A{
public:
int operator ()(){
return 123;
}
operator int(){
return 345;
}
};
void print(A a){
cout << a() << endl;
}
int main(){
A b = A();//直接对象
cout << b() << endl;
print(A());//传入对象
A a;
cout << a() << endl;
//cout << A() << endl;//如果仅仅只是重载了括号,compile error A()相当于构造A对象吗?
cout << A() << endl;//强制类型转换
return 0;
}
D:\programming\C++>g++ TestOperatorQuote.cpp
D:\programming\C++>a
123
123
123
345