实例类型转换

最后更新于:2022-04-02 02:07:15

[TOC] ## 实例类型转换
main.cpp ``` #include #include using namespace std; class ABC { public: int age; string name; ABC(int a,string n):age(a),name(n) { } operator int() // ABC -> int { return age; } operator string() // ABC -> string { return name; } }; int main() { ABC abc(12,"idcpj"); cout << abc+12 <
';