I was was wondering if anyone knows if it's possible to use inheritance within a union somehow.
In the example below, the TestFails
union will not contain the a
variable within the Base
struct, while TestWorks
does work.
struct Base { int a; };
union TestFails
{
struct : public Base {};
int b;
};
union TestWorks
{
struct { int a; };
int b;
};
int main()
{
TestWorks works;
works.a = 0;
TestFails fails;
fails.a = 0;
return 0;
}
You can test the code here: http://ideone.com/dUzpOR