Things that cannot be inherited

I was asked to name three things that cannot be inherited from the base class.

Besides private member functions, what else can I add?

I thought about the functions of friends, but since they actually do not belong to the class, they have nothing to do with inheritance.

+4
source share
2 answers

A few obvious ones that you usually care about are constructors, assignment operators, and destructors.

In all these cases, the new version related to the derived class is either provided by the user or synthesized by the compiler (although C ++ 11 also adds some features for things like simply deleting one of them, you want to have access).

I probably should add that β€œyou cannot inherit” is not necessarily accurate. For example, inheriting constructors are added in C ++ 11 (but they were not in C ++ 98/03, which most courses still deal with). Even in C ++ 11, you do not inherit them by default.

+8
source

Private member variables and private bases. You also cannot inherit template arguments, COM __uuids, and if you are not exporting a class from a DLL.

Assignment operators cannot be inherited.

0
source

All Articles