I have found out that unions are classes in c++.
If you declare a class as a union:
union Foo // Declare union type
{
char ch;
int func(int a);
};
Will the size of the union be 4 or 1 (assuming char size of 1 and pointers size of 4 ) ?
No (they are a class-type, not classes).My bad, apparently they are classes:3.9.2/1
(no longer relevant) Unions can’t have
virtualmember functions & also can’t be used in inheritance.Onto the answer:
The size will be large enough to accommodate the largest data member. In this case, it will likely be
1, yes.