What can you have in a class declaration that you will never encounter in a union declaration?

I saw this question online interview. Unfortunately, I can’t understand such a thing ... functions, constructor, destructors

btw, I think the structure and class are almost the same in C ++, except that class members are private by default, while structure members are public by default. Inheritance between classes is also private by default, and inheritance between structures is public by default.

And the union is different from the structure, because all the members are in one place.

thanks

+4
source share
1 answer

A union cannot have base classes.

A join cannot also contain any data members with non-trivial special member functions, virtual member functions, static data elements, or reference data, but they will appear in the definition of the join. A union cannot be used as a base class, but this applies only to other class declarations, and not to the declaration of the union itself.

+6
source

Source: https://habr.com/ru/post/1337889/


All Articles