home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18917 < prev    next >
Encoding:
Text File  |  1993-01-11  |  2.2 KB  |  70 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: <1993Jan11.045542.6877@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: <1ikg2tINN2d3@news.cerf.net> <1993Jan9.154850.5939@ucc.su.OZ.AU> <1ipp5oINNg0e@news.cerf.net>
  11. Date: Mon, 11 Jan 1993 04:55:42 GMT
  12. Lines: 56
  13.  
  14. In article <1ipp5oINNg0e@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
  15. >In article <1993Jan9.154850.5939@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  16. >>In article <1ikg2tINN2d3@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
  17. >>>>>WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
  18. >>>>>OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
  19. >>>>>CLASS A. 
  20. > -- stuff deleted --
  21. >>>
  22. >>>I still do not see a reason for inheritance when containment will do.
  23. >>>Can anybody clarify this???
  24. >>>
  25. >>
  26. >>    Sure. If you use containment you end up counting
  27. >>subobjects of the base classes too:
  28. >>
  29. >>    class X { A<X> ax; };
  30. >>    class Y { A<Y> ay; };
  31. >>    class Z { A<Z> az; };
  32. >>
  33. >>    Z z;
  34. >>
  35. >>// WOOPS: now we count 1 Z (correct) and 1 X and 1 Y (wrong)
  36. >
  37. >Have you missunderstood, and thought that there is only one static
  38. >created for all of the A's. (I think) you are wrong here. The template
  39. >semantics create one static for each class and A<X> is a different class
  40. >from A<Y> so thge result would be 1 Z , zero X's, and zero Y's.
  41. >
  42.     Sorry: I messed the example!
  43. Try again:
  44.  
  45.     class X { A<X> ax; };
  46.     class Y { A<Y> ay; };
  47.     class Z {
  48.         A<Z> az;
  49.         X x;        // containment!
  50.         Y y;
  51.     };
  52.     Z z;
  53.  
  54. Now the count for 'X' objects is 1. 
  55.  
  56.     class ZZ : public X, public Y { // inheritance
  57.         A<Z> az;
  58.     };
  59.     ZZ zz;
  60.  
  61. Now the count for 'X' objects is 2.
  62.  
  63. I'm assuming in this case you want Z==1, ZZ==1, X==0, Y==0?
  64.  
  65. -- 
  66. ;----------------------------------------------------------------------
  67.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  68.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  69. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  70.