🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2393

Re: Continue: static func() const; legal?

#2393
From: Matt Austern
Date: Thu, 02 Nov 1995 02:30
31 lines
2321 bytes
In article <478k57$5gl@stellar.comnet.com> Bret Pehrson <BretP@strata3d.com> writes:

> Now, since cLumps is a member of base, albeit static, making a static 
> member function 'const' would mean that it does not change available 
> class members (in this case, static member variables).
> 
> So, with this above sample, I can definitely see a legitimate need 
> for static const member functions.

The thing you have to remember is that static member variables really
aren't particularly special in any way: from section 9.5.2 of the
draft standard it's pretty clear that static member variables are
almost exactly the same as global variables, except that the are in
class scope instead of namespace scope, and they obey class access
rules.

There's no way to declare a function such that it's prohibited from
modifying global variables; similarly, there's no way to declare a
function such that it's prohibited from modifying static member
variables.  Static member variables are really a notational
convenience more than anything else: pretty much anything you can do
with static member variables, you can also do with global variables
declared in a namespace.
-- 
  Matt Austern                             He showed his lower teeth.  "We 
  matt@physics.berkeley.edu                all have flaws," he said, "and 
  http://dogbert.lbl.gov/~matt             mine is being wicked."

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MATT.95Nov1162611@cyclops5.berkeley.edu>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <478k57$5gl@stellar.comnet.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: matt@cyclops5.berkeley.edu (Matt Austern)
Newsgroups: comp.std.c++
Subject: Re: Continue:  static func() const;  legal?
Date: 2 Nov 1995 02:30:01 GMT
Organization: University of California at Berkeley (computational neuroscience)
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <MATT.95Nov1162611@cyclops5.berkeley.edu>
References: <478k57$5gl@stellar.comnet.com>
Reply-To: matt@physics.berkeley.edu
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: cyclops5.berkeley.edu
In-Reply-To: Bret Pehrson's message of 1 Nov 1995 20:34:14 GMT
Content-Length: 1386
Originator: clamage@taumet