Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!glacier.ics.uci.edu!schmidt From: schmidt@glacier.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c++ Subject: Static data members in C++ classes Message-ID: <1449@paris.ics.uci.edu> Date: 13 Dec 88 04:07:51 GMT Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Organization: University of California, Irvine - Dept of ICS Lines: 76 References: Hi, I realize the following point has been raised here before, but I'm still not entirely sure of the official party line. Simply put, which sections of the following example are legal C++? ---------------------------------------- class foo { private: static int foobar; // Is this correct? My guess is yes. public: foo ( int i ) { foobar = i; } }; class bar { public: static const int k = 10; // Is this correct? My guess is yes. static foo i = 9; // Is this correct? My guess is no! static foo j; // Is this correct? My guess is no! bar ( ): j( 10 ) { ; } }; ---------------------------------------- On page 275 of the 1986 reference manual it states that: ``No initializer can be specified for a static member, and it cannot be of a class with a constructor.'' The wording of the second part in the preceding sentence had mislead me, and others, to believe that the first use of static in class foo ( i.e., static int foobar ) was incorrect. However, I no longer believe that is true, since it appears that this sentence actually refers to the latter part of class bar above, with static foo j being a primary example of the proscription quoted from the manual. ************************************************** Am I safe and correct in making these assumptions? ************************************************** Finally, CC 1.2.1 gives the following diagnostics for the above program: ---------------------------------------- CC foo.C: "foo.C", line 18: sorry, not implemented: static member bar::i with initializer "foo.C", line 18: sorry, not implemented: static member bar::i of class foo with constructor "foo.C", line 18: sorry, not implemented: static member bar::j of class foo with constructor "foo.C", line 18: sorry, not implemented: member initializer for static bar::j 4 errors ---------------------------------------- Since the error message wording is ``sorry, not implemented'' rather than ``error, illegal construct'' does this imply that these features are likely to appear in subsequent versions of the compiler? For example, how does CC 2.0 handle the test case presented above? Thanks for your help. Doug Schmidt P.S. What this newsgroup needs are more participants like Chris Torek and Henry Spencer in comp.lang.c, who always seem to have concise and thoughtful answers to the most wonderfully obscure questions ;-). -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.