Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!ames!haven!adm!lhc!nih-csl!alw.nih.gov!kgorlen From: kgorlen@alw.nih.gov (Keith Gorlen) Newsgroups: comp.lang.c++ Subject: Re: Nonvirtual base classes in MI Message-ID: <959@nih-csl.nih.gov> Date: 9 Feb 91 13:37:59 GMT References: <1174@zinn.MV.COM> <64173@brunix.UUCP> Sender: news@nih-csl.nih.gov Reply-To: kgorlen@alw.nih.gov (Keith Gorlen) Organization: National Inst. of Health Lines: 29 In article <64173@brunix.UUCP>, sdm@cs.brown.edu (Scott Meyers) writes: |> In article <1174@zinn.MV.COM> mjv@objects.mv.com (Michael J. Vilot) writes: |> | I agree with Keith, and with Tom Cargill, that private base classes can be |> | transformed into class members. There may be some minor performance |> | differences between the two, but I suspect on average it's a wash. |> |> No no no. You lose virtual functions when you turn inheritance into member |> containment. There is a conceptual distinction between the following: |> |> A has a member B ==> A "has a" B (or A "contains a" B) |> A publicly inherits from B ==> A "is a" B |> A privately inherits from B ==> A "is implemented in terms of a" B |> |> Private inheritance is a convenient way to share code when there is no |> other conceptual relationship between two classes. I usually call this |> "code stealing." When stealing the code in another class, you often have |> to do some class specific stuff; this is where virtual functions come in. |> The member functions in the (private) base class can call virtual functions |> to do the customization. This won't work with member objects, because they |> have no way of knowing what they're a part of. |> That sounds like a good reason to me! -- 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