home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Downcasting (was: Re: run-time type checking)
- Message-ID: <1992Aug16.061849.28208@ucc.su.OZ.AU>
- Keywords: polymorphism, RTTI, downcasts.
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Aug5.110132.8756@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU> <1992Aug14.165432.14403@mole-end.matawan.nj.us>
- Date: Sun, 16 Aug 1992 06:18:49 GMT
- Lines: 65
-
- In article <1992Aug14.165432.14403@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
- >> operator Derived1*() { return this; }
- >> };
-
- Aslo,
-
- class Base {
- downcastable D1, D2;
- ...
-
- >
- >The problem with this is that it requires explicit functions all over
- >the place.
-
- The second form requires it only in the base class.
- (Downcastability is obviously inherited)
-
- >It swells the interfaces (trust me, I've seen it used, even
- >suggested it as the best possible in C++ today), swells the vtables,
-
- If we use RTTI it doesnt impact the system beyond
- what RTTI would anyway.
-
- >may
- >thereby interefere with some language implementations, and makes the
- >code brittle.
- >
- >But I like the idea of declarations in the derived type permitting or
- >blocking an RTTI-based conversion.
-
- The problem with putting the permission in the derived class
- is that it doesn't solve the original problem (if there was one)
- that being able to downcast from a base violates the BASE classes
- integrity.
-
- My premise is that the MOTHER of an object (the code
- doing the 'new') knows the objects exact type (secret name),
- and has control over who gets hold of it (when you
- know an objects secret name you have total power over it,
- elementary principle of magic, and isn't programming just a
- form of magic :-)
-
- At this level, downcastability is easily controlled on
- an object by object basis, the MOTHER making a list of
- {Base*, Derived*}
- and passing the list to trusted confidants dynamically.
- The declaration 'downcastable D' in the base class B is
- equivalent to puting the list in a static variable in the
- base class--everone with access to the base is granted
- permission to downcast to the nominated derived class,
- which is now an integral part of the base classes interface.
-
- Other methods of passing around secret names include
- tagged pointers, which have the advantage of static type
- correctness that no other method has. Because of this
- IMHO tagged pointers should be implemented anyhow, since they
- are the best mechanism available when they actually do
- the job (which is not always).
-
-
- --
- ;----------------------------------------------------------------------
- TIM (TAL) LISTER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-