用AI赚第一桶💰低成本搭建一套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/>