home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20045 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.7 KB

  1. Xref: sparky comp.lang.c++:20045 comp.object:5099
  2. Newsgroups: comp.lang.c++,comp.object
  3. 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
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: HELP : Array of objects of diff classes ??
  6. Message-ID: <1993Jan27.171812.1886@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1993Jan19.112059.2882@ucc.su.OZ.AU>> <CAMPBELL.93Jan22132319@analysis.src.honeywell.com> <mcampbel.727881449@eola.cs.ucf.edu>
  11. Date: Wed, 27 Jan 1993 17:18:12 GMT
  12. Lines: 52
  13.  
  14. In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
  15. >campbell@src.honeywell.com (Terry Campbell) writes:
  16. >>> There is an object class called Holder. The object holder can hold various
  17. >>> things : Pencils, Pens, Erasers etc. I`ve declared different classes for
  18. >>> these things ( class PENCIL, class PEN, class ERASER etc. ). 
  19. >>>
  20. >I've been following this thread with some interest, and I find your reply 
  21. >interesting.  
  22. >
  23. >I agree with your analysis of the problem re: subclasses, however, what if
  24. >you buy/purchase/steal classes from multiple vendors/coworkers/victims ?
  25. >They necessarily will not have a common base class.  (Or is this correctly
  26. >deemed "superclass?")
  27.  
  28.     Best not to use the words 'superclass' and 'subclass' in C++.
  29. Stick to 'base' class and 'derived' class.
  30.  
  31. >
  32. >Borland does this - they have a common base class, "Object", as I recall, and
  33. >all of the storage classes can hold 'objects'.  This allows the storage 
  34. >classes to hold just about anything in their provided class library, as every-
  35. >thing is derived from the 'object' class.
  36.  
  37.     They USED to do this in the older and hopefully now
  38. defunct class library. The newer BIDS library does not use this
  39. woeful technique :-)
  40.  
  41. >
  42. >Any ideas/thoughts from anyone on how to handle dissimilar base classes in a
  43. >'holder' class?
  44. >
  45.     As I originally posted, you use the construct that
  46. was designed to IMPOSE similarity on disimlar classes,
  47. namely the humble union. You will have to add some type information
  48. to the union:
  49.  
  50.     struct WritingTool {
  51.         enum {tPen, tPencil, tEraser } tag;
  52.         union {
  53.             Pen pen;
  54.             Pencil pencil;
  55.             Eraser rubber;
  56.         };
  57.     };
  58.  
  59. It would be better IMHO if this was supported directly by the compiler.
  60.  
  61. -- 
  62. ;----------------------------------------------------------------------
  63.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  64.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  65. ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
  66.