🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1942

static class members

#1942
From: 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
Technical Details
Message-ID: <8905040129.AA13063@notecnirp.Princeton.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!tut.cis.ohio-state.edu!PRINCETON.EDU!staelin

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!tut.cis.ohio-state.edu!PRINCETON.EDU!staelin
From: staelin@PRINCETON.EDU (Carl Staelin)
Newsgroups: gnu.g++.bug
Subject: static class members
Message-ID: <8905040129.AA13063@notecnirp.Princeton.EDU>
Date: 4 May 89 01:29:32 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 44