Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!sdcc6!odin!bruss From: bruss@odin.ucsd.edu (Brian Russ) Newsgroups: comp.lang.c++ Subject: More About Static Members Message-ID: <12372@sdcc6.ucsd.edu> Date: 22 Aug 90 16:43:26 GMT References: Sender: news@sdcc6.ucsd.edu Distribution: comp Organization: CSE Dept., U. C. San Diego Lines: 31 Nntp-Posting-Host: odin.ucsd.edu In article ssimmons@convex.com (Steve Simmons) writes: > > > class GROUP > { > private: > int notShared; > static int shared; > public: > GROUP() : { if (shared == 0) doFirstInstanceStuff(); }; > }; > > int GROUP::shared = 0; // Initialize here ^^^ Two questions. First, is the 'int' declaration needed here? 'shared' is already known to be an int, I thought ... Secondly (this may be GNU C++ specific) I can't get the above to work (regardless of the 'int' issue) unless 'shared' is declared as public. This seems to contradict Lippman, who says that the, uh, "see-ability" (can't think of the proper term) of a static member (i.e. is it public or private) affects access but *not* initialization. GNU C++, however, will complain about the "Initialize here" line, claiming that "shared" is a private member. Am I missing something here? -- Brian Russ CSE Department, UC San Diego ..!sdcsvax!bruss bruss@beowulf.ucsd.edu