1. It could save and waste space. If a union object is reused to hold different members, it could save space. Otherwise it most likely wastes space because it can only hold one value at a time. If the value is the biggest element, it does not save or waster space. If the value is not the biggest one, it actually waste space.
3. No matter what value it hold, they start at same address. That is the key advantage of union.
2. The reason of not allowing classes with contructor/destructor is to avoid memory corruption and leak. When an instance is being created, if members have constructors, they have to be called. Calling one constructor after another (from difference class) will lead to memory corruption. For example:
class A
{
public:
A() { _ip = new int; _i = 10; }
~A() { delete _ip; }
private:
int *_ip, _i;
};
class B
{
public:
B() { _i = 10; _ip = new int; }
~B() { delete _ip; }
private:
int _i, *_ip;
};
If you have a union with members of A and B, no matter which constructor is called first, the second constructor will corrupt the memory. By the same token, union members with destructor will cause memory problem too.
Yes, you can. But only the classes without user defined constructor or destructor are allowed. I have explained why the restriction is needed here earier this year. If you need it, I will try to explain it again.