Does C++ allow multiple levels of virtualness?

By : Lewis
Source: Stackoverflow.com
Question!

I have a base class called Object. PhysicsObject inherits from Object. Ball inherits from PhysicsObject, and SoftBall inherits from Ball. Something like this:

Object
 |
PhysicsObject
 |
Ball
 |
SoftBall

I have a method called foo() that is declared virtual in Object (given an implementation, so not pure virtual), then declared and implemented as virtual again in PhysicsObject and Ball. Finally, SoftBall implements foo() again without declaring it as virtual.

If I have an Object* that points to a SoftBall, will SoftBall's version of foo() be called? If not, is there any way to achieve this effect? Basically, does this aspect of polymorphism still work over more than one level of inheritance?

By : Lewis


This video can help you solving your question :)
By: admin