C++变体的实现代码

#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;
}




有什么问题欢迎留言!~~~~


猜你喜欢

转载自blog.csdn.net/qq_36818386/article/details/80266183
今日推荐