Victor Bazarov wrote:
Steven T. Hatton wrote: [...]
As I understand things, a virtual function invocation is a lookup in a
vtbl followed by an access to the actual function being executed.
Only if the call is made through a variable declared as a pointer or
a reference. If the call is made for an _object_ directly, as in
MyPolymorphicClass anObject;
anObject.someVirtualFunction(); // no vtbl lookup occurs
or if the function is explicitly classified
MyPolymorphicClass anObject;
anObject.MyBase::someVirtualFunction(); // no vtbl lookup occurs
there is no lookup-and-redirection. The call is "statically" linked to
the appropriate function.
> I guess he
could mean that a derived class would have its own vtbl pointing to its
baseclass, etc., and that the "chain of base class calls" is the process
of climbing up that vtbl stack.
I didn't see that. I am not sure why you think that.
V
I think I figured out what he mean. He was suggesting the chain of calls
was like this (going backwards):
class Base{
virtual void f() {
//do something
}
}
class Derived: public Base {
void f() {
Base::f();
// do more stuff
}
};
class DerivedDerived: public Derived {
void f() {
Derived::f();
// do more stuff
}
};
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell