Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!exodus!morocco.Eng.Sun.COM!landauer From: landauer@morocco.Eng.Sun.COM (@morocco.eng [Doug Landauer]) Newsgroups: comp.lang.c++ Subject: Re: C++ Static Members and Inheritance Keywords: C++ Static Members Inheritance Message-ID: <12533@exodus.Eng.Sun.COM> Date: 30 Apr 91 17:50:58 GMT References: <5069@servax0.essex.ac.uk> Sender: news@exodus.Eng.Sun.COM Distribution: all Organization: Sun Microsystems, Mt. View, Ca. Lines: 39 > Now I know that a static member is the same for every object of a class, > but is the same for every object of a DERIVED class? My two objects were > not of class "base" but of classes "derived1" and "derived2" respectively. The whole point of inheritance (public inheritance, at least) is that the derived "is a" base, so that you can use the derived object as if it were a base object. The static member is shared among all instances (objects) of the base class, including the embedded "base" object that lives inside each derived object. > I've searched literature high and low for an answer to this. Nowhere do > they mention what happens when you inherit a static member (data or > function). Yeah, I think you're right -- I can't find a particularly explicit mention either of this particular issue (inheritance vs static members), or of the general principle that a derived "is a" base. Perhaps X3J16's editor could add a sentence or two to make these things more clear. Here's the things I found that came closest to these issues: E&S, Section 9.4: There is only one copy of a static data member, shared by all objects of the class in a program. E&S, Section 10: A derived class can itself serve as a base class ... E&S, Section 11.2: Specifying a base class "private" does not affect access to static members of the base class. (Note that the latter has been rewritten a bit in the current draft -- it says something more like Because of the rules on pointer conversion (section 4.6), a static member of a private base class may be inaccessible as an inherited name, but accessible directly. now. But remember that it's still just a Draft.) -- Doug Landauer - Sun Microsystems, Inc. - Languages - landauer@eng.sun.com