Path: utzoo!mnetor!tmsoft!torsqnt!jarvis.csri.toronto.edu!rutgers!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: static member initialization (lippman's book) Message-ID: <9928@alice.UUCP> Date: 20 Sep 89 00:49:29 GMT References: <292@mez.e-technik.uni-bochum.de> Distribution: comp Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 37 In article <292@mez.e-technik.uni-bochum.de>, frei@mez.e-technik.uni-bochum.de (Matthias Frei) writes: > I've a question to the scope of static members in Rel. 2.0. > On page 441 lippman provides an example on static member initialization: > > class Y { > ... stuff deleted > private: > static int val; > }; > int Y::val = 1; > Is the statement Y::val = 1 a bug in the book, or are the scope rules > from Rel 1.2 invalid ? I think val is private to Y and is seen inside > the class only. The book is correct. > If that statement is legal, I hope it only may occur once near by > the class definition. Or can I assign in this way everywhere ? It may occur only once in the entire program, although that once may be anywere. It is exactly analagous to this: class X { private: void f(); }; void X::f() { /*...*/ } Surely you won't object to the definition of the function member X::f even though it's private. Why, then, should you object to a similar definition of a data member? -- --Andrew Koenig ark@europa.att.com