Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!apple!agate!shelby!neon!pescadero.Stanford.EDU!philip From: philip@pescadero.Stanford.EDU (Philip Machanick) Newsgroups: comp.lang.c++ Subject: Class instance variables (was Re: inheriting statics) Message-ID: <1990Nov14.212657.5671@Neon.Stanford.EDU> Date: 14 Nov 90 21:26:57 GMT References: <1990Nov13.072057.18707@Neon.Stanford.EDU> Sender: news@Neon.Stanford.EDU (USENET News System) Reply-To: philip@pescadero.stanford.edu Organization: Computer Science Department, Stanford University Lines: 39 In article <1990Nov13.072057.18707@Neon.Stanford.EDU>, I wrote: |> I had what I thought was a good idea for structuring a program. I had a |> class called Object at the top of the hierarchy, and my idea was that I |> would isolate low-level stuff in this layer. [stuff deleted] |> My initial attempt was to define (detail left out) |> |> class Object |> { ... static *Object free_list; ... }; |> |> What I wanted was that this static member would automatically be reinstatiated |> for each derived class. Unfortunately, this is not how things work: there is |> exactly one copy of free_list for Object and all classes derived from it. I had 2 replies on to this, one from Ralph Johnson (johnson@cs.uiuc.edu) pointing out that whqt I really wanted was class instance variables, in the style of Smalltalk, and another from Joe Pallas (pallas@alydar.Eng.Sun.COM) pointing out that the NIH library has a macro you are meant to put in every class declaration. In both cases (and in the approach I am actually using), it seems you have to put something in every class you define to get the effect I want. My understanding of the way Smalltalk works is each class is implemented as an object containing class instance variables and methods, as well as specifying what an object of that class should look like. C++ is different - a class is merely compile-time information; although static members may be referenced through a class name, this is really scoping information. Even taking this into account, would it not be possible for static data members to be a bit more like Smalltalk class instance variables (i.e., derived classes have new copies, rather than sharing static data members with base classes)? I assume this question has been looked at by the language designers. However, I believe that the use of macros in libraries like NIH (and I believe ET++) suggests there is room for improvement in the language design. If there has been a previous discussion of this on the net that I missed, I would appreciate an e-mail or 2. -- Philip Machanick philip@pescadero.stanford.edu