#include "stdafx.h" #include "Varient.h" ostream& operator<<(ostream& out, CVarient& obj) { if (obj.m_nType == TYPE_INT) { out << obj.m_Un.m_n; } else if (obj.m_nType == TYPE_CONSTCHARPTR) { out << obj.m_Un.m_str; } return out; } int main(int argc, char* argv[]) { // auto n = 1; // auto str = "Hello World!"; CVarient n = 1; //CVarient这个类的构造和析构函数不用写 CVarient str = "Hello World!"; n = n + 2; cout << str << endl; return 0; }
有什么问题欢迎留言!~~~~