[gnu.g++.bug] static class members

staelin@PRINCETON.EDU (Carl Staelin) (05/04/89)

I have a suggestion regarding the design of C++.  Stroustrup allows
classes to have static class members, which are shared by all
instances of that object.  However, he restricts these static members
to be objects which do not have constructors (Stroustrup page 275).  I
suggest that this restriction be eased somewhat to include at least
those objects with default constructors.  I don't know if it is easy
or possible to ease the restriction further by using rules similar to
global variable declarations.

for example:

class A
{
 public:
  A();
  ~A();

  do_something();
    ...
};

class B
{
 public:
  static A shared_object;

  B();
  ~B();

  do_something_else();
    ...
};	

In particular this is exceedingly useful in a threaded environment
where class A is a shared data structure, such as a set or a tree, and
where it is not "reasonable" for A to be a global object.  In other
words, arguments similar to the arguments used regarding the
usefulness of static class members without constructors are equally
applicable to the usefulness of static class members with
constructors.

Carl Staelin

staelin@princeton.edu