[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Scope of static member initializers



My pet peeve with C++ is that (accordong to CFront and a too-close
reading of the AT&T language description) initializers for static data
members of a class are in the public scope, rather than the scope of
the class.  Thus in a situation like this:

class groupmember {
   public:
      static const groupmember zero;
      ...

Zero can only be initialized through a public constructor, and even
that constructor cannot be given any constants private to the class.

As a remedy, I propose:

1) That the initializer of a data member have access to all members of
the class.

2) That when the type of a static data member of a class is the class
itself, aggregate initialization (e.g., {0,0,0}) be allowed.

3) That when the type of a static data member of a class is the class
itself, ctor-initializers (e.g., :baseclass(17),somemember(0)) be
allowed, provided that if any members are ctor-initialized, no
aggregate initialization may follow.

Aggregate initialization of structs and classes is something I've
always found awkward (and non-robust), so I wouldn't really mind
seeing it dropped entirely in favor of ctor-initializers -- although
for the sake of the past, I suppose it must be kept.

					--Tom Lippincott
					  lippin@xxxxxxxxxxxxxxxxx

   "Every action of theirs, that seems to them an act of their own free
    will, is ... in bondage to the whole course of previous history."
					--Leo Tolstoi