Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!nosc!cod!mball From: mball@cod.NOSC.MIL (Michael S. Ball) Newsgroups: comp.lang.c++ Subject: Re: static members Message-ID: <1354@cod.NOSC.MIL> Date: 7 Jan 89 04:25:24 GMT References: <701@cadillac.CAD.MCC.COM> Reply-To: mball@cod.nosc.mil.UUCP (Michael S. Ball) Organization: Naval Ocean Systems Center, San Diego Lines: 39 In article <701@cadillac.CAD.MCC.COM> rpj%cad@MCC.COM (Rich Johns) writes: > >In Stroustroup on page 275, section 8.5.1 it states: > > "No initializer can be specified for a static member, > and it cannot be of a class with a constructor." > >2) You cannot have a static data member which needs a > constructor. This is the correct interpretation. A type which has a constructor must be initialized, and there is no defining point for a static member where the compiler could put the initializer. > a) a static data member is allowed, as long as: > 1) the member does not require a constructor. > 2) the member is private There is no restriction on access. It can be public, protected or private. > b) a static const data member is allowed, as long as: Hard to see what use it is, except as a source of constant zero. usually constants must be initialized. > c) a static const data member CAN have an initial value. Only the default value of zero. > d) a static function member is not allowed. True. All of these answers apply to existing implementations of the language (cfront 1.2 ore equal). There were discussions of ways to change them at the USENIX workshop, so they should not be considered the last word. Mike Ball TauMetric Corporation