home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18337 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.3 KB  |  62 lines

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