Strange Behaviour Class Objects Inside Union

前端 未结 3 1231
情歌与酒
情歌与酒 2020-12-29 14:30

Hi I wanted know the reasons of the following code

void main()
{
  class test
  {
    public:
      test(){}
      int k;
  };

  class test1
  {
    public:         


        
3条回答
  •  悲&欢浪女
    2020-12-29 15:03

    In C++, unions may not contain classes with (non-trivial) constructors or destructors. This is because the compiler has no means of telling which constructor or destructor to use when a union instance is created or destroyed.

提交回复
热议问题