home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18881 < prev    next >
Encoding:
Text File  |  1993-01-09  |  2.0 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Restatement and clarification of "static inheritance" question
  5. Message-ID: <1993Jan9.154850.5939@ucc.su.OZ.AU>
  6. Keywords: inheritance
  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: <1993Jan8.154446.17174@dayfac.cdc.com> <1993Jan8.174434.7714@ucc.su.OZ.AU> <1ikg2tINN2d3@news.cerf.net>
  11. Date: Sat, 9 Jan 1993 15:48:50 GMT
  12. Lines: 50
  13.  
  14. In article <1ikg2tINN2d3@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
  15. >>>WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
  16. >>>OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
  17. >>>CLASS A. 
  18.  
  19. >>There are a number of possible ways that might fix this using templates.
  20. >>You would have to do something like:
  21. >>
  22. >>    class B : public virtual A<B> { ...
  23. >>
  24. >>which seems dubious. Then the template class A<T> could create
  25. >>the int A<T>::counter automagically. Dont know if this
  26. >>works.
  27. >>
  28. >
  29. >I still do not see a reason for inheritance when containment will do.
  30. >Can anybody clarify this???
  31. >
  32.  
  33.     Sure. If you use containment you end up counting
  34. subobjects of the base classes too:
  35.  
  36.     class X { A<X> ax; };
  37.     class Y { A<Y> ay; };
  38.     class Z { A<Z> az; };
  39.  
  40.     Z z;
  41.  
  42. // WOOPS: now we count 1 Z (correct) and 1 X and 1 Y (wrong)
  43.  
  44. In fact: if you actually WANT to count subobjects, then
  45. DO use containment.
  46.  
  47. Do you want to count 'new'ed classes or ALL subobjects?
  48.  
  49. Wait! It is WORSE:
  50.  
  51.     class Q { X x; Y y; A<Z>; };
  52.  
  53. This counts 1 'X' object: for BOTH containment (shown) or
  54. the inheritance method.
  55.  
  56. OH! You have posed a really HARD problem. 
  57. Mm .. overload operator new??
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.