Code:
struct A{
int a;
virtual void f(){}
};
union B{
A ob;
};
Compile-time Error:
C:\to\main.cpp|9|error: member 'A B::ob' with constructor not allowed in union|
C:\to\main.cpp|9|error: member 'A B::ob' with copy assignment operator not allowed in union|
||=== Build finished: 2 errors, 0 warnings ===|
c++03 Standard:
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, nor can an array of such objects. If a union contains a static data member, or a member of reference type, the program is ill-formed.
The standard doesn't say anything about an object of a class with a virtual function, and from the error, the compiler complain about constructor and copy-assignment operator which I didn't use. so is this a compiler bug ? Im using gcc .