Multilevel inheritance C++

Viewed 365

Suppose a class C inherits from a class B which overrides a virtual function defined in A. C does not override the function. When a pointer of type A* points to an object of type C, will the function call use the overridden version in B?

3 Answers

Yes!

Semantically, C inherits its implementation from B implicitly.
Concretely, the implementation of a virtual function that's called is the most derived available one.

When a pointer of type A* points to an object of type C, will the function call use the overridden version in B?

Yes.

Yes the function call will use the overridden version in B, unless you implement the virtual function in C. In that case, the function call will be of C.

Related