Search Menu



Problem : Why is inheritance important?

Inheritance is a key feature of the C++ programming language. It lets a programmer create more and more specific versions of a class, avoiding the need for recoding. Inheritance is important for reusability, an important goal of object oriented programming.

Problem : How do I call a member function that was inherited from another class?

If the member function of the base class was public or protected you can usually access it just as you might access a member function of the derived class. If two member functions share the same name, you must use the scope operator to specify which class's function you need to use. Of course, if the member function of a base class was declared private, it cannot be accessed directly.

Problem : When might you use multiple inheritance?

If an object needs to have the traits of more than one other class, it should inherit the data and functions of all the different classes necessary. For instance, if you want an object that represents a picture being displayed in a window, then the class might inherit the properties of a "picture class" and of a "window class."

Problem : Why is use of the scope operator important?

The scope operator is important when using multiple inheritance because it makes it clear to the compiler (and to programmers) which data member or function you are referring to.

Problem : What problem does using the virtual keyword fix?

The virtual keyword is used if there is a possibility that two versions of the same "grandparent" base class will be inherited by a derived class. Virtual tells the compiler to use only one copy of the grandparent, to avoid ambiguity.