home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20045 comp.object:5099
- Newsgroups: comp.lang.c++,comp.object
- Path: sparky!uunet!news.univie.ac.at!scsing.switch.ch!univ-lyon1.fr!ghost.dsi.unimi.it!rpi!usc!howland.reston.ans.net!spool.mu.edu!yale.edu!newsserver.jvnc.net!darwin.sura.net!sgiblab!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: HELP : Array of objects of diff classes ??
- Message-ID: <1993Jan27.171812.1886@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: <1993Jan19.112059.2882@ucc.su.OZ.AU>> <CAMPBELL.93Jan22132319@analysis.src.honeywell.com> <mcampbel.727881449@eola.cs.ucf.edu>
- Date: Wed, 27 Jan 1993 17:18:12 GMT
- Lines: 52
-
- In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
- >campbell@src.honeywell.com (Terry Campbell) writes:
- >>> There is an object class called Holder. The object holder can hold various
- >>> things : Pencils, Pens, Erasers etc. I`ve declared different classes for
- >>> these things ( class PENCIL, class PEN, class ERASER etc. ).
- >>>
- >I've been following this thread with some interest, and I find your reply
- >interesting.
- >
- >I agree with your analysis of the problem re: subclasses, however, what if
- >you buy/purchase/steal classes from multiple vendors/coworkers/victims ?
- >They necessarily will not have a common base class. (Or is this correctly
- >deemed "superclass?")
-
- Best not to use the words 'superclass' and 'subclass' in C++.
- Stick to 'base' class and 'derived' class.
-
- >
- >Borland does this - they have a common base class, "Object", as I recall, and
- >all of the storage classes can hold 'objects'. This allows the storage
- >classes to hold just about anything in their provided class library, as every-
- >thing is derived from the 'object' class.
-
- They USED to do this in the older and hopefully now
- defunct class library. The newer BIDS library does not use this
- woeful technique :-)
-
- >
- >Any ideas/thoughts from anyone on how to handle dissimilar base classes in a
- >'holder' class?
- >
- As I originally posted, you use the construct that
- was designed to IMPOSE similarity on disimlar classes,
- namely the humble union. You will have to add some type information
- to the union:
-
- struct WritingTool {
- enum {tPen, tPencil, tEraser } tag;
- union {
- Pen pen;
- Pencil pencil;
- Eraser rubber;
- };
- };
-
- It would be better IMHO if this was supported directly by the compiler.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph: 2 799 8223 --------
-