Xref: utzoo comp.lang.c++:7846 gnu.g++:874 Path: utzoo!attcan!uunet!mcsun!ukc!keele!nott-cs!gas From: gas@cs.nott.ac.uk (Alan Shepherd) Newsgroups: comp.lang.c++,gnu.g++ Subject: static data members and derived classes (AT&T v g++) Message-ID: <50037@robin.cs.nott.ac.uk> Date: 31 May 90 08:57:40 GMT Sender: root@cs.nott.ac.uk Reply-To: gas@cs.nott.ac.uk (Alan Shepherd) Organization: Computer Science, Nottingham Univ., UK. Lines: 35 I apologize if I'm asking a lot of banal questions, but no-one seems to answer ! I'd rather have 60 answers than none at all. I would like the position regarding static members and derived classes clarified. Consider a class 'a' with a protected static int 'number': class a { protected: static int number; } Now derive a class `b' from 'a': class b: public a { } From my understanding of the AT&T reference manual for release 2.0 ($11.5), I should now be able to refer to b::number. Unfortunately, cfront complains that b doesn't have a member 'number'. This doesn't appear to make sense. However, g++ compiles fine, but does something even more peculiar. int a::fred =3; int b::fred =4; The above two statements leave both a and b with the value 3 for fred. However, during normal execution (i.e. after main) changing the value of a::fred or b::fred sets them both to be the same value. This means that there is definitely a bug in the way g++ initialises the static members before main and the policy seems odd. I would rather have class 'b' inherit its own distinct static member. Alan Shepherd