🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Carl Staelin Thu, 04 May 1989 01:29
static class members
#1942
Author: Carl Staelin
Date: Thu, 04 May 1989 01:29
44 lines
1564 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads