Topic: Initialization of private static members


Author: girod@tele.nokia.fi (Marc Girod)
Date: Tue, 15 Dec 1992 13:23:24 GMT
Raw View
Hi net world!

------------------------------------------------------------
// stinit.C

class A {
  private:
    A();
    static A a;
};

A A::a; //HP CC v 3.0: error: global scope cannot access A::A(): private  member (1298)
        //
        //GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
        //stinit.C: In function `void  _GLOBAL_$I$_1A$a ()':
        //stinit.C:5: constructor `A::A ()' is private
        //stinit.C:7: in base initialization for class `A'

------------------------------------------------------------

The ARM states p 180 that 'Static members obey the usual member access
rules except that they can be initialized (in file scope)'.

This allows a private static member to be initialized, as long as the
constructor for its class is public.

Are my compilers correct in refusing me the access to private
constructors, to build a private static member?

Sorry if this has already been dealt with...

Best Regards!
--
+-----------------------------------------------------------------------------+
| Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
| TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
| SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
|    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
+-----------------------------------------------------------------------------+