home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18106 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.1 KB  |  55 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: static members in derived classes
  5. Message-ID: <1992Dec16.192147.1378@microsoft.com>
  6. Date: 16 Dec 92 19:21:47 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec12.175244.17775@taumet.com> <1992Dec14.215407.21631@microsoft.com> <1992Dec15.150612.28264@wam.umd.edu>
  9. Lines: 44
  10.  
  11. In article <1992Dec15.150612.28264@wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes:
  12. |I don't see how it follows that allowing "virtual static" data dictates
  13. |a particular implementation. 
  14.  
  15. If you are not presuming a particular implementation of virtual statics,
  16. consider then an implementation that implements them in a manner as-if similar
  17. to the following:
  18.  
  19. #include <stdio.h>
  20.  
  21. class A
  22. {
  23.     static int _a;
  24. public:
  25.     int& s;
  26. protected:
  27.     A(int& aa) : s(aa) {}
  28. public:
  29.     A() : s(_a) {}
  30. };
  31. int A::_a = 1;
  32.  
  33. class B : public A
  34. {
  35.     static int _b;
  36. public:
  37.     B() : A(_b) {}
  38. };
  39. int B::_b = 2;
  40.  
  41. main()
  42. {
  43.     A a;
  44.     B b;
  45.  
  46.     printf("a.s = %d, b.s = %d\n", a.s, b.s);
  47.  
  48.     return 0;
  49. }
  50.  
  51. ======
  52.  
  53. But, this particular implementation is *already* available to you,
  54. and far from hard to program.
  55.