Topic: Redundant Code in Stroustrup's Virtual Inheritance Examples?
Author: jdp@polstra.com (John Polstra)
Date: 1 Jul 1994 17:19:28 -0700 Raw View
In Stroustrup's examples of multiple inheritance with virtual base
classes, I keep seeing something that seems redundant to me. Am I
missing something?
An example on page 262 of "The Design and Evolution of C++" presents
a diamond-shaped inheritance lattice, i.e.,
W
/ \
/ \
/ \
AW BW
\ /
\ /
\ /
CW
In the example, Stroustrup presents the following code:
class W { ... };
class AW : public virtual W { ... };
class BW : public virtual W { ... };
class CW : public AW, public BW, public virtual W { ... };
^^^^^^^^^^^^^^^^
WHY???
What is the purpose of the "public virtual W" in the declaration of
class CW? Does it make any difference at all? It seems to me that the
virtual inheritance from W is implied anyway, because both of CW's base
classes (AW and BW) already have W as a virtual base class.
I have tried the example (the whole thing, of course) with 4 different
compilers, and they all behave the same way. It doesn't make any
discernable difference whether that final "public virtual W" is present
or absent.
Again: Am I missing something?
--
John Polstra jdp@polstra.com
John D. Polstra & Co., Inc. Phone (206) 932-6482
Seattle, Washington USA Fax (206) 935-1262
"Self-knowledge is always bad news." -- John Barth
Author: kanze@us-es.sel.de (James Kanze US/ESC 60/3/164 71425)
Date: 06 Jul 1994 20:13:38 GMT Raw View
In article <2v2bqg$9mc@seattle.polstra.com> jdp@polstra.com (John
Polstra) writes:
|> In Stroustrup's examples of multiple inheritance with virtual base
|> classes, I keep seeing something that seems redundant to me. Am I
|> missing something?
|> An example on page 262 of "The Design and Evolution of C++" presents
|> a diamond-shaped inheritance lattice, i.e.,
|> W
|> / \
|> / \
|> / \
|> AW BW
|> \ /
|> \ /
|> \ /
|> CW
|> In the example, Stroustrup presents the following code:
|> class W { ... };
|> class AW : public virtual W { ... };
|> class BW : public virtual W { ... };
|> class CW : public AW, public BW, public virtual W { ... };
|> ^^^^^^^^^^^^^^^^
|> WHY???
|> What is the purpose of the "public virtual W" in the declaration of
|> class CW? Does it make any difference at all? It seems to me that the
|> virtual inheritance from W is implied anyway, because both of CW's base
|> classes (AW and BW) already have W as a virtual base class.
|> I have tried the example (the whole thing, of course) with 4 different
|> compilers, and they all behave the same way. It doesn't make any
|> discernable difference whether that final "public virtual W" is present
|> or absent.