home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18844 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  1.4 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usc!news.cerf.net!nic.cerf.net!hlf
  2. From: hlf@nic.cerf.net (Howard Ferguson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Restatement and clarification of "static inheritance" question
  5. Date: 8 Jan 1993 18:10:37 GMT
  6. Organization: CERFnet Dial n' CERF Customer Group
  7. Lines: 38
  8. Sender: hlf@cerf.net
  9. Message-ID: <1ikg2tINN2d3@news.cerf.net>
  10. References: <1993Jan8.154446.17174@dayfac.cdc.com> <1993Jan8.174434.7714@ucc.su.OZ.AU>
  11. NNTP-Posting-Host: nic.cerf.net
  12. Keywords: inheritance
  13.  
  14. >>WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
  15. >>OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
  16. >>CLASS A. 
  17. >
  18. >    class A {
  19. >        int & counter;
  20. >    public:
  21. >        A(int& c) : counter(c) {++counter;}
  22. >        ~A() { --counter; }
  23. >    };
  24. >
  25. >    class B : public virtual A {
  26. >        static int counter;
  27. >    public:
  28. >        B() : A(counter) { ... }
  29. >    };
  30. >
  31. >    int B::counter=0;
  32. >
  33. >Without templates. Exercise: Prove it works! Prove you cannot
  34. >get away without declaring and defining the counter in
  35. >each class manually.
  36. >
  37. >There are a number of possible ways that might fix this using templates.
  38. >You would have to do something like:
  39. >
  40. >    class B : public virtual A<B> { ...
  41. >
  42. >which seems dubious. Then the template class A<T> could create
  43. >the int A<T>::counter automagically. Dont know if this
  44. >works.
  45. >
  46.  
  47. I still do not see a reason for inheritance when containment will do.
  48. Can anybody clarify this???
  49.  
  50.     hlf
  51.  
  52.