Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpl-opus!hpnmdla!hpmwtd!jeffa From: jeffa@hpmwtd.HP.COM (Jeff Aguilera) Newsgroups: comp.lang.c++ Subject: Re: another Zortech bug? Message-ID: <1520020@hpmwjaa.HP.COM> Date: 12 Feb 90 23:25:26 GMT References: <4800083@m.cs.uiuc.edu> Organization: HP Microwave Tech. - Santa Rosa, Ca. Lines: 36 > ... > 2. > Buried deep in the innards of Stroustrup is this little rule that says that > objects that have a constructor may not be used as static data members of a > class. This means that you may not have the associative_array as a static > member of Id, even though this would be stylistically correct. I can think > of no reason for this dumb rule, but I didn't design the language. This is wrong. The rule is in section 9.4 of the Reference Manual: "Static members of a class declared local to some FUNCTION have no linkage and cannot have static members that require initialization (except for the default "all zeros" initialization (Section 8.4))." Static members with constructors are permitted within a CLASS. The declaration should be given within the .h file, and the initialization in the .c file. Example: //X.h class X { static Y y; }; //X.c Y X::y = ...; Unfortunately, Zortech 2.0 botches some static member initializations, especially when the static member is an array. Perhaps Walter can list the case known not to work. I had an example under 2.0 that resulted in multiple invokations of the constructor and destructor for a static member. The problem disappeared with 2.06. (The original example did not involve virtual inheritance. This case is still broken.) ---- jeffa