C++ Inheritance

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is a pure virtual function?

A base class can contain virtual functions that are have no definition but instead are assigned the value 0. That class is then an abstract class, and any derived classes must provide a definition for the pure virtual methods.

What is virtual inheritance?

A class can be inherited with virtual inheritance ( : virtual public Base) which indicates that only a single copy of the base class should be present in any derived classes.

What is a virtual method?

A method in a class can be marked virtual. It can then be overridden by a derived class. If one then would call the virtual method on the object through a pointer of type Base, the derived's method would still be called.

Describe private inheritance.

All inherited public and protected members will have access-specifier private in the derived class.

Describe public inheritance.

All inherited public members will stay public, the protected members will stay protected and the inherited private members will be inaccessible in the derived class (as usual).

Explain the friend keyword.

The friend keyword can be used to declare a class, function, function/class template as friend. These can be defined outside the class scope and still have access to private and protected members. It doesn't matter under which access-specifier the friend class is declared, the effect is always the same.

Describe Protected inheritance.

When using protected inheritance, all public and protected members in the base class is protected in the derived class. Protected access is similar to private, but the members can also be accessed by derived classes.


Ensembles d'études connexes

Accounting Senior Sem Midterm pt 2

View Set

State Laws, Rules, and Regulations

View Set

Ch. 37: Management of Patients With HIV Infection and AIDS

View Set

Science 9 Deped Unit: 2. EARTH'S ATMOSPHERE

View Set