Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!mips!dimacs.rutgers.edu!rutgers!bellcore-2!bellcore!coupe!garnett From: garnett@coupe.bellcore.com (Michael Garnett) Newsgroups: comp.lang.c++ Subject: Re: virtual base class & function member ambiguity question Message-ID: <1990Aug28.163333@coupe.bellcore.com> Date: 27 Aug 90 20:03:33 GMT References: Sender: news@bellcore.bellcore.com Reply-To: garnett@thumper.bellcore.com Organization: Information Networks Research (Bellcore) Lines: 67 In article , brucec@phoebus.phoebus.labs.tek.com (Bruce Cohen;;50-662;LP=A;) writes: |> Is this a bug in cfront 2.0, or am I not understanding how virtual base |> classes work? |> |> Question 1: |> I have a simple test case with an inheritance DAG that goes like: |> |> Root |> | |> Derived |> _____|_____ |> | | |> DerivedVR1 DerivedVR2 |> |_________| |> | |> Leaf |> ... |> Here's the file: |> // test virtual base function inheritance ... |> |> class DerivedVR1 : public Derived |> { |> public: |> DerivedVR1(char* s = "DerivedVR1"); |> }; |> DerivedVR1::DerivedVR1(char* s) : Derived (s) { } |> |> class DerivedVR2 : public Derived |> { |> public: |> DerivedVR2(char* s = "DerivedVR2"); |> }; |> DerivedVR2::DerivedVR2(char* s) : Derived (s) { } |> |> class Leaf : public virtual DerivedVR2, public virtual DerivedVR1 |> { |> public: |> Leaf(char* s = "Leaf"); |> void PrintLeaf(); |> I'm answering this in a hurry but... shouldn't the class DerivedVR1 be class DerivedVR1 : public virtual Derived ... and the DerivedVR1 class likewise be class DerivedVR2 : public virtual Derived ... and the class Leaf be simply class Leaf : public DerivedVR1, public DerivedVR2 reason: (possible reason? ) It's the 'Derived' class that you want to avoid multiple copies of.. ...not the DerivedVR2 and DerivedVR1 classes... Each of them (DerivedVR[12]) must have a copy of Derived ... ...but Leaf needs only one copy.... ...yet still needs BOTH DerivedVR1 and DerivedVR2 Michael