22.5.  Review Questions

[ fromfile: inheritance-detail-questions.xml id: inheritance-detail-questions ]

  1. What is a vtable?

      It is a virtual jump table - it can be implemented as a list of pointers to all methods (virtual functions) of a class.

  2. What is a polymorphic type?

      A class with at least one virtual function. A class which has a vtable.

  3. Which kinds of member functions are not inherited? Why?

      They are copy constructors, copy assignment operators, and destructors. It is not appropriate to inherit these methods because they must perform operations on each member of the derived class, and the base class knows nothing about derived class types. Each of these functions are auto-generated for classes which do not supply one.

  4. Under what circumstances should you have virtual destructors?

      When operating on a collection of polymorphic types, as long as there is one method, there should be a virtual destructor.

  5. What happens when a virtual function is called from a base class constructor?

      Dynamic binding does not happen. The compiler will resolve the call at compile time, meaning that the derived override will never be called from a base class constructor.

  6. What is virtual inheritance? What problems can it be used to solve?

      virtual inheritance makes it possible to avoid multiply-inheriting the same class, when it appears as more than one base's base class.

  7. Why would you use nonpublic derivation?

      It is very similar to having a non-public subobject, but it becomes possible to inherit methods that are only accessible in the class itself (and derived classes, if it is protected derivation)