Lowest point in inheritance tree need not be virtual?

http://ideone.com/Bjfxl
Is is any faster than if B::go were virtual?
Last edited on
Hm... I'm not sure if that's supposed to happen, but I am fairly sure that it's not faster. If you're calling go on an A, and A declares go as virtual, then it would have to do the lookup in the table anyways, no? Maybe it's faster if you're calling go on a B though. Either way, it shouldn't have any significant performance impact.
Last edited on
go is virtual in B automatically because go is virtual in the base class A.
@Peter87: wow, I did not expect this behavior.
http://ideone.com/zGYyK
I thought that a non-virtual member function in C++ was equivalent to a final method in Java. Guess this doesn't trace down the inheritance tree but instead jump straight to the exact type.

Does anyone know how to get the effect of tracing down the inheritance tree and stopping at a non-virtual member function? I have been designing all my classes under the assumption that it worked this way...
Topic archived. No new replies allowed.