#include <iostream>
#include <string>
using namespace std;

class CAnyType //: public CObject
{
public:
    CAnyType(){};
    //DECLARE_SERIAL(CAnyType)
    ~CAnyType(){};

protected:
    
    string DataType;
    // union还可以用来判断大端还是小端
    union{
        int myint;
        double mydouble;
        float myfloat;
        wchar_t mychar;} value;

public:
    CAnyType operator=(const int &in){value.myint=in;DataType="int";return *this;}
    CAnyType operator=(const wchar_t &in){value.mychar=in;DataType="char";return *this;}
    CAnyType operator=(const float &in){value.myfloat=in,DataType="float";return *this;}
    CAnyType operator=(const double &in){value.mydouble=in;DataType="double";return *this;}
	friend std::ostream & operator<<(std::ostream &os, const CAnyType& ca){
		os << ca.value.mydouble << std::endl;
		return os;
	};
};

int main()
{
    using namespace std;
    CAnyType test = CAnyType();
    test = 55;
    cout << test;
    return 0;
}




相关文章:

  • 2022-01-02
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-02-13
  • 2021-12-24
猜你喜欢
  • 2021-06-24
  • 2021-06-09
  • 2021-12-19
  • 2021-12-14
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案