What if I have this:
union{ vector<int> intVec ; vector<float> floatVec ; vector<double> doubleVec ; } ;
Of course, I’ll be using just one of the 3 vectors. But… what happens when all the 3 vectors are contructed??
Would the consructors of the 3 vectors interfere with each other?? (since the 3 of them are in the same memory address)
Thanks.
Current C++ standard does not allow non-POD types inside unions. You will get this compiler error from
gcc:New C++ standard (C++0x) proposes unrestricted unions, but it adds yet more object lifetime pitfalls to C++.