home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1788 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.9 KB  |  53 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!funic!nokia.fi!tele.nokia!girod
  3. From: girod@tele.nokia.fi (Marc Girod)
  4. Subject: Initialization of private static members
  5. Message-ID: <GIROD.92Dec15152324@node_262d6.tele.nokia.fi>
  6. Sender: usenet@noknic.nokia.fi (USENET at noknic)
  7. Nntp-Posting-Host: rat.ts.tele.nokia.fi
  8. Reply-To: marc.girod@ntc.nokia.com
  9. Organization: kpd
  10. Distribution: comp
  11. Date: Tue, 15 Dec 1992 13:23:24 GMT
  12. Lines: 39
  13.  
  14. Hi net world!
  15.  
  16. ------------------------------------------------------------
  17. // stinit.C
  18.  
  19. class A {
  20.   private:
  21.     A();
  22.     static A a;
  23. };
  24.  
  25. A A::a; //HP CC v 3.0: error: global scope cannot access A::A(): private  member (1298)
  26.         //
  27.         //GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
  28.         //stinit.C: In function `void  _GLOBAL_$I$_1A$a ()':
  29.         //stinit.C:5: constructor `A::A ()' is private
  30.         //stinit.C:7: in base initialization for class `A'
  31.  
  32. ------------------------------------------------------------
  33.  
  34. The ARM states p 180 that 'Static members obey the usual member access
  35. rules except that they can be initialized (in file scope)'.
  36.  
  37. This allows a private static member to be initialized, as long as the
  38. constructor for its class is public.
  39.  
  40. Are my compilers correct in refusing me the access to private
  41. constructors, to build a private static member?
  42.  
  43. Sorry if this has already been dealt with...
  44.  
  45. Best Regards!
  46. --
  47. +-----------------------------------------------------------------------------+
  48. | Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
  49. | TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
  50. | SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
  51. |    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
  52. +-----------------------------------------------------------------------------+
  53.