Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uakari.primate.wisc.edu!ctrsol!ginosko!uunet!odi!valens!dlw From: dlw@odi.com (Dan Weinreb) Newsgroups: comp.lang.c++ Subject: Re: Can you initialize private static data members? Message-ID: <404@odi.ODI.COM> Date: 31 Jul 89 13:23:41 GMT References: <11327@brunix.UUCP> Sender: news@odi.com Reply-To: dlw@odi.com Lines: 43 In-reply-to: jps@cs.brown.edu's message of 26 Jul 89 20:30:41 GMT In article <11327@brunix.UUCP> jps@cs.brown.edu (John Shewchuk) writes: From: jps@cs.brown.edu (John Shewchuk) Date: 26 Jul 89 20:30:41 GMT Organization: Brown Computer Science Given: class X { ... public: X(char *); // The only constructor } and class Y { private: static X x; public: ... } Is there any way to initialize Y::x? The references seem to indicate that Y::x can not be initialized by saying X Y::x("Test"); because Y::x is private. Is this correct? No; there's an exception to the access rules so that it can be initialized. According to the Product Reference Manual, page 60, sec 9.4: "Static members obey the usual class member access rules, except that they can be initialized (in file scope)." Experimentation on a simple test case shows that this works properly in Cfront 2.0. Thanks to our local C++ language expert, Sam Haradvala, for researching this and checking it out. Dan Weinreb Object Design, Inc. dlw@odi.com