ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 实例类型转换 <details> <summary>main.cpp</summary> ``` #include <iostream> #include <string> 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 <<endl; // 24 string abcstr=abc; cout << abcstr <<endl; // idcpj return 0; } ``` </details> <br/>