Rahul wrote:
Hi Everyone,
I have the following union declarations,
union sample
{
int p;
virtual void fun();
void display(); // accessing value of p...
};
From the standard [9.5/1]:
... A union can have member functions (including constructors and
destructors), but not virtual (10.3) functions.
The declaration of "sample" is therefore invalid.
Now assuming that the size of int is 4 bytes and that of a pointer
too is four bytes, would it work as expected?
What is expected? There is no pointer in "sample".
memory of the union is the same as that of the largest member of the
union...
From the standard [9.5/1]:
... The size of a union is sufficient to contain the largest of its data
members. ...
As far as I can see, this only gives a lower bound for the size.
Best
Kai-Uwe Bux