home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pmafire!news.dell.com!natinst.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Virtual base classes
- Message-ID: <1992Dec23.154929.7674@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <724475492snx@trmphrst.demon.co.uk> <449@genie.UUCP>
- Date: Wed, 23 Dec 1992 15:49:29 GMT
- Lines: 65
-
- In article <449@genie.UUCP> roger@genie.UUCP (Roger H. Scott) writes:
- >In article <724475492snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
- >>In article <445@genie.UUCP> roger@genie.UUCP (Roger H. Scott) writes:
- >>> If Kludge is a non-public subclass of WellFormed then there
-
- Please say 'base' and 'derived' or you'll confuse me.
- I assume you mean that WellFormed is a private base of Kludge?
-
- >>> isn't much point in talking about Kludge redefining WellFormed's virtual
- >>> functions since you can't use a Kludge in a place where a WellFormed is
- >>> expected (i.e., who would ever have hold of a Kludge and send it one of
- >>> WellFormed'd messages, other than a member function of Kludge?).
- >>
- >>Imagine that WellFormed's constructor adds all WellFormeds to some
- >>Collection of WellFormeds. Notice that all Kludges will also be added to
- >>this collection. Now imagine some calling some virtual function for all
- >>WellFormeds in the Collection.
- >
- >This seems to raise an interesting question: does there exist an Is-A
- >relationship between Kludge and WellFormed,
-
- If this was intended, Kludge should have been derived
- using public virtual inheritance:
-
- class Kludge : public virtual WellFormed { ..
-
- >and if not, what does it mean to
- >have a collection of objects that *claim* to be WellFormeds but are in fact
- >Kludges?
-
- If we have
-
- class Kludge : private WellFormed { ...
-
- it is not so easy to obtain a pointer to the WellFormed to put
- in the collection. In particular, a cast by the public wont work
- because WellFormed is a private base.
- Given that WelFormed is closed and locked away in
- the library, how would Kludge get access to the WellFormed subobjects
- address?
-
- Can Kludge perform the cast?
-
- WellFormed *Kludge::GetWellFormed()const
- { return (WellFormed*)this;}
- // legal ??
-
- >Do we see a small whole in the type system here, where within
- >member functions inherited from a non-public base class an object which
- >is in fact a Kludge can be used interchangably with an object that is a
- >WellFormed (the example cited by Nikki uses the base class's constructor, but
- >any member function of the base class will do)? I'd like to see some sort
- >of comprehensive statement about the (intended? actual?) semantics of non-
- >public inheritance in C++.
-
- The statement is just the ARM. For a critique try
-
- "A Critique of the Inheritance Principles of C++" by
- Markku Sakinnen, Computing Systems Vol 5 No 1.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-