Q: Example from the Holy Writ

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

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
}
 
R

rock

test
pctv06 said:
..fgn,;lgm;
Steven T. Hatton said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top