From -9108278199480602321
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,23a9d1bd670d3257
X-Google-Attributes: gidf78e5,public
From: JHB NIJHOF <nijhojhb@aston.ac.uk>
Subject: Re: Multiple inheritance and base class access with repeated bases
Date: 1998/05/20
Message-ID: <6jt7ub$71u$1@whatsit.aston.ac.uk>#1/1
X-Deja-AN: 354870531
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <01bd8309$63568200$3aace5cf@dave>
Delivered-To: comp-std-c++@news.pipex.net
X-Original-Date: 20 May 1998 00:25:47 GMT
Organization: Aston University
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBEAgUANWJ83eEDnX0m9pzZAQFhAwF3YDVgVvqdB7WlnjKp3zq1sOITH8he9voO qZ8gH3ZQ152MAcIsCtvOBcVtVNtg/Dc= =GiuP
User-Agent: tin/pre-1.4-980226 (UNIX) (Linux/2.0.33 (i686))
Newsgroups: comp.std.c++


Dave J.G. <see@signa.ture> wrote:
: While testing an object streaming class I've been working on, I came up with this
: monster:

: Class A { public: int i ; } ;
: Class B : public A { public: int i ; } ;
: Class C : public A, public B { public: int i ; } ;
: Class D : public A, public B, public C { public: int i ; } ;

: This compiles okay ( with a 'repeated base' warning and a couple of
derogatory : comments from the compiler ) but when I try to access
D::A::i in a method ( not : shown ) of Class D, I get an ambiguous
base error.

No wonder. Class has 8 members i, four of which which are
from class A: 
A = (Ai)
B = ((Ai) Bi)
C = ((Ai) ((Ai) Bi) Ci)
D = ((Ai) ((Ai) Bi) ((Ai) ((Ai) Bi) Ci))
So the compiler cannot figure out which of the i-s from class A you want.
Try virtual base clases.

-- 
Jeroen Nijhof      J.H.B.Nijhof@aston.ac.uk 
Accordion Links    http://www-th.phys.rug.nl/~nijhojhb/accordions.html
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



