Object-Oriented Programming

C++ Inheritance Specifiers

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Classes

Client

Output

Problems:

  • A non-const does not override a const
  • Name of a method hides (not overrides)

(Partial) Solution: override

override Notes

  • override is a specifier
  • Acts as a contextual keyword and you are still allowed to use override as an identifier, e.g., int override = 0;
  • Style Note: May replace declaration of virtual in derived classes
  • General Note: Instead of guessing, experiment

Classes

final Notes

  • On a class, enforces that we cannot derive from the class
  • On a method, enforces that we cannot override the method