




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The derived class can provide its own version of a function that appears in the base class. (Note that a function is determined by its name.
Typology: Exercises
1 / 8
This page cannot be seen from the preview
Don't miss anything!





We saw the following:
Base *R = new Derived(); // okay
To use the member functions of Derived, one has to “remind” the compiler that we know that the object R is pointing to is a Derived object:
Derived Q = static_cast<Derived> (R);
If a function is labeled virtual in the Base class, then the Derived version of a function is always used.
Otherwise, which version is used is determined by how the object is referenced. (We omit the details.)
Note that if a function is labeled virtual in the Base class, it is automatically virtual in the Derived class.
In Java all functions are implicitly virtual
A virtual function might have no implementation at all in the Base class. This is indicated by writ- ing
virtual void scream( ) = 0;
in the class definition.
An abstract base class is one with at least one pure function. We cannot instantiate an object of an abstract base class.
(Java: An interface is a class without mem- ber variables all of whose member functions are pure.)