M
Maarten Kronenburg
"Rolf Magnus" wrote in message
it like x.f1() or p->f1(). But calling x.B::f1() or p->B::f1() I think means
calling the class B version, no matter what the runtime type of the object
(see [class.virtual]).
virtual function sense.
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.4
then I think it is a little less, more like 2 extra indirections
(fetch,fetch,call).
runtime type of the object can change. As mentioned this is also more or
less suggested by Item 24 in More Effective C++, the picture on page 120.
But in the standard in [class.virtual] item 7: "The interpretation of the
call of a virtual function depends on the type of the object for which it is
called (the dynamic type), whereas...". In my opinion, when using two vtable
pointers in one object, the dynamic type is no longer unique for an object,
but can change, which I think is not mentioned in the standard.
If I say:
Base *p = new Derived3();
no matter how many times the object is (multiply) derived, I expect that
object to remain of the same run-time type (Derived3) during its lifetime.
The compile-time type of the pointer can of course be changed with casts,
but as mentioned this should as far as I know not change the vtable pointer,
that is the run-time type. This is why I think that an object can have only
one vtable pointer.
Regards, Maarten.
Yes, but the runtime type version (via vtable) is only called when callingHowever, it is needed for B::f1().
it like x.f1() or p->f1(). But calling x.B::f1() or p->B::f1() I think means
calling the class B version, no matter what the runtime type of the object
(see [class.virtual]).
Yes that seems me to be correct. The data members are never virtual in theThat offset can be determined at compile time.
virtual function sense.
When I read:However, that usually resolves to three levels of pointer indirections.
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.4
then I think it is a little less, more like 2 extra indirections
(fetch,fetch,call).
It seems to me that when using two vtable pointers in one object, then the
runtime type of the object can change. As mentioned this is also more or
less suggested by Item 24 in More Effective C++, the picture on page 120.
But in the standard in [class.virtual] item 7: "The interpretation of the
call of a virtual function depends on the type of the object for which it is
called (the dynamic type), whereas...". In my opinion, when using two vtable
pointers in one object, the dynamic type is no longer unique for an object,
but can change, which I think is not mentioned in the standard.
If I say:
Base *p = new Derived3();
no matter how many times the object is (multiply) derived, I expect that
object to remain of the same run-time type (Derived3) during its lifetime.
The compile-time type of the pointer can of course be changed with casts,
but as mentioned this should as far as I know not change the vtable pointer,
that is the run-time type. This is why I think that an object can have only
one vtable pointer.
See my comment above.It explains how vtables are handled by GCCs C++ front end, especially for
multiple and virtual inheritance. That should explain it.
The dynamic_cast doesn't have to return the same address your provided. It
might add an offset.
Regards, Maarten.