home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18842 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.9 KB  |  59 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: <1993Jan8.174434.7714@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>
  11. Date: Fri, 8 Jan 1993 17:44:34 GMT
  12. Lines: 45
  13.  
  14. In article <1993Jan8.154446.17174@dayfac.cdc.com> pault@dayfac.cdc.com (Paul Thompson;DAYFAC-ITS;) writes:
  15. >First off, thanks to all those who responded to my question and my
  16. >apologies for not being clear. I probably should have chosen a different
  17. >phrasing of the problem and certainly should have explained it better!
  18. >First to answer the replies received so far and I will clarify.
  19.  
  20.     You missed mine?
  21. >WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
  22. >OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
  23. >CLASS A. 
  24.  
  25.     class A {
  26.         int & counter;
  27.     public:
  28.         A(int& c) : counter(c) {++counter;}
  29.         ~A() { --counter; }
  30.     };
  31.  
  32.     class B : public virtual A {
  33.         static int counter;
  34.     public:
  35.         B() : A(counter) { ... }
  36.     };
  37.  
  38.     int B::counter=0;
  39.  
  40. Without templates. Exercise: Prove it works! Prove you cannot
  41. get away without declaring and defining the counter in
  42. each class manually.
  43.  
  44. There are a number of possible ways that might fix this using templates.
  45. You would have to do something like:
  46.  
  47.     class B : public virtual A<B> { ...
  48.  
  49. which seems dubious. Then the template class A<T> could create
  50. the int A<T>::counter automagically. Dont know if this
  51. works.
  52.  
  53. -- 
  54. ;----------------------------------------------------------------------
  55.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  56.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  57. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  58.