The class Chevrolet inherits from the class Automobile. Both have implemented a function called DownShift(). Suppose carPtr is declared as: Automobile *carPtr;
The carPtr object can point to both a Chevrolet or an Automobile. We want the call carPtr -> DownShift() to call the right version of DownShift based on what carPtr points to. We must:

a) declare DownShift virtual in class Chevrolet
b) declare DownShift virtual in class Automobile
c) make the inheritance public
d) make the inheritance private


I think the answers are "a & b".
If it's only one side virtual then the compiler chooses the wrong version, right?

You only need to declare a function as virtual at the highest level. Any child classes will implicitly declare the same function as virtual, so there's no need for an explicit declaration, but it never hurts to be explicit. So b is the required answer and a is optional.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.