[comp.lang.c++] inheriting statics

philip@pescadero.Stanford.EDU (Philip Machanick) (11/13/90)

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. Specifically, I wanted to
make a general low-level memory allocator at this level. Among other
things, this allocator would require a free list for each derived class,
since derived classes are not necessarily the same size.

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 am
landed with having to redefine the free list in each derived class, which breaks
my attempt at isolating the low-level stuff in the class Object. I can think of
other schemes, but none as simple and straightforward as what I wanted in the
first place: reinstantiation of static members in each subclass.

Since starting with class Object at the top of the hierarchy is hardly original, maybe someone has already solved this problem. If so, I'd be interested in
hearing about the solution.
-- 
Philip Machanick
philip@pescadero.stanford.edu