Path: utzoo!attcan!uunet!spool.mu.edu!samsung!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!haven!adm!lhc!nih-csl!helix.nih.gov!kgorlen From: kgorlen@helix.nih.gov (Keith Gorlen) Newsgroups: comp.lang.c++ Subject: Re: Nonvirtual base classes in MI Message-ID: <911@nih-csl.nih.gov> Date: 1 Feb 91 19:14:02 GMT References: <1159@zinn.MV.COM> <63176@brunix.UUCP> Sender: news@nih-csl.nih.gov Reply-To: kgorlen@helix.nih.gov (Keith Gorlen) Lines: 56 In article <63176@brunix.UUCP>, sdm@cs.brown.edu (Scott Meyers) writes: |> In reponse to my posting, Michael J. Vilot described his uses of nonvirtual |> base classe with MI. His examples were interesting, but I didn't see any |> uses of a DAG. Perhaps I wasn't explicit enough in what I was looking for. |> What I want to see is an example that can be boiled down to this: |> |> A class A { ... }; |> / \ |> / \ |> B C class B: public (or private) A { ... }; |> \ / class C: public (or private) A { ... }; |> \ / |> D class D: (optionally virtual) public (or private) B, |> (optionally virtual) public (or private) C { ... }; |> |> What's important here is that neither B nor C inherits from A as a virtual |> base. That results in the memory layout of a D object looking like this, |> at least conceptually: |> |> +------------+ |> | B's A Part | |> +------------+ |> | B Part | |> +------------+ |> | C's A Part | |> +------------+ |> | C Part | |> +------------+ |> | D Part | |> +------------+ |> |> Notice that there are two A parts in a D object. |> Then I would draw the DAG like this: A A | | B C \ / D Examples 13-1 and 13-2 in "Data Abstraction and Object-Oriented Programming in C++" show multiply inheriting from class Link so that derived classes can be threaded on multiple linked lists; i.e. class A = Link, class B = AllLink, class C = QLink, and class D = Vehicle. However, Tom Cargill's article in the most recent issue of "The C++ Journal" shows how to do this example without using MI. -- Keith Gorlen phone: (301) 496-1111 Building 12A, Room 2033 FAX: (301) 402-0007 National Institutes of Health uucp: uunet!kgorlen%alw.nih.gov Bethesda, MD 20892 Internet: kgorlen@alw.nih.gov