5.9. Defining a Derived Class Virtual Function
When we define a derived class, we must decide whether to override or inherit each of the base class virtual functions. If we inherit a pure virtual function, the derived class is then also considered an abstract class, and no independent objects of the class can be defined.
If we choose to override the base class instance, the prototype of the derived class instance must match the base class protoype exactly: the parameter list and the return type and whether the virtual function is const or non-const. For example, the following definition of Fibonacci::what_am_i() is not quite right:
class Fibonacci : public num_sequence { public: virtual const char* what_am_i() // not quite right ... { return ...
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.