Is it possible to put several objects together inside a union?

后端 未结 6 1930
无人及你
无人及你 2021-02-08 06:38

What if I have this:

union{
    vector intVec ;
    vector floatVec ;
    vector doubleVec ;
} ;

Of cours

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 07:00

    From the C++ Standard, section 9.5:

    An object of a class with a non-trivial constructor (12.1), a non-trivial copy constructor (12.8), a non-trivial destructor (12.4), or a non-trivial copy assignment operator (13.5.3, 12.8) cannot be a member of a union,

    Here, for "non-trivial" read "useful" :-)

提交回复
热议问题