This is from the C++ Standard: ISO/IEC 14882:2003(E)
Any deviation from the text in the Standard document is an unintentional
transcription error on my part. I'm fairly confident about the reasoning
behind every part except the line with the comment // does not declare f.
I'm not sure if it is merely pointing out that no f is declared in the
definition of VB1a, or suggesting something more subtle. I believe the
former is the case, and the intent of the example is to show VB2::f()
overrides the virtual A::f(). Da then inherits the overridden f from VB2.
This is the DAG of what I think is happening.
A has virtual f()
/ \
/ \
/ \
VB1a no f() VB2 overrides f()
\ /
\ /
\ /
Da inherits f() from VB2
I am I understanding this correctly?
/*
The following example shows a function that does not have a unique
final overrider:
*/
struct A {
virtual void f();
};
struct VB1 : virtual A { // note virtual derivation
void f();
};
struct VB2 : virtual A {
void f();
};
/*
struct Error : VB1, VB2 { // ill-formed
};
*/
struct Okay : VB1, VB2 {
void f();
};
/*
Both VB1::f and VB2::f override A::f but there is no overrider of
both of them in class Error. This example is therefore
ill-formed. Class Okay is well formed, however, because Okay::f is a
final overrider.
The following example uses the well-formed classes from above.
*/
struct VB1a : virtual A { // does not declare f
};
struct Da : VB1a, VB2 {
};
void foe() {
VB1a* vb1ap = new Da;
vb1ap->f(); //calls VB2::f
}
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org