home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:11682 comp.std.c++:977
- Newsgroups: comp.lang.c++,comp.std.c++
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!mips!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
- Message-ID: <1992Jul28.183746.24287@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: <1992Jul24.234628.21196@cadsun.corp.mot.com> <1992Jul25.172045.24675@ucc.su.OZ.AU> <BryL9q.K5I@watcgl.waterloo.edu>
- Date: Tue, 28 Jul 1992 18:37:46 GMT
- Lines: 41
-
- In article <BryL9q.K5I@watcgl.waterloo.edu> rhbartel@watcgl.waterloo.edu (Richard Bartels) writes:
- >As long as the downcasting discussion is open again,
- >the example we are confronting which requires something like
- >that, we think, is the issue of input from disk.
- >
- >I would love to have a solution that did not require the cop-out of
- >isA() and cast/convert.
- >
- >Consider the classic "List" class and "ListNode" class.
- >ListNode is a base class, and assume there are two flavors
- >of derived node. We write a List that contains a mix of
- >these nodes out to a file; now we want to read the List back
- >in and reconstruct it.
- >
- >Can it be done without resorting to an isA() member function,
- >some member data to identify node type, and possibly some
- >casting/conversion?
-
- a) without some type information, it cant be done.
- b) without casting it can (and should :-) be done
-
- union hetero {
- type1 *p1;
- type2 *p2;
- };
-
-
- And the list is homogeneous--all the elements are of type 'hetero'.
-
- >
- >What's the authoritative answer?
-
- Dont know. Who's the authority?
-
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-