class B { public: //隐式转换 B(int i) { cout << i << endl; data = i; } //仿函数 bool operator() (int i) { cout << i << endl; return i > 0; } //转换函数 operator string() { return "class_string"; } private: int data; }; int main() { B inst = 100; bool temp = inst(-100); if (temp) { cout << "hello operator" << endl; } string str = inst; cout << str << endl; getchar(); return 0; }
时间: 2025-01-13 04:10:05