Article View: comp.std.c++
Article #2423Re: class member: static name const; Legal?
From: Joe Buck
Date: Sat, 04 Nov 1995 09:39
Date: Sat, 04 Nov 1995 09:39
54 lines
2421 bytes
2421 bytes
Jason Merrill writes:
> Nope; the 'const' qualifier affects the 'this' parameter to
> a member function, so applying it to a static member
> function is meaningless.
bashford@scripps.edu (Don &) writes:
> Thanks Jason, I've wondered about that too. If you can't mix
> static and const, what way do we have of promising that a static
> member function will not alter static data? If there is no
> way at the moment, perhaps the standard should provide one.
There isn't a way, other than
// This function does not alter static data
But note that a regular const member function may alter the static members
of a class with impunity:
class Foo {
private:
static const Foo * last_object_accessed;
public:
void some_func() const {
last_object_accessed = this;
}
};
This fact makes me curious whether those asking for "static const" member
functions are confused about what "const" means for normal member
functions. It doesn't mean that the function is side-effect-free
(it would often be able to tell compilers *that*, since it helps
so much with optimization).
There are many important distinctions relevant to design that do not
correspond to keywords in standard C++, and I don't think the language
should attempt to address them all (e.g responsibility for deleting
objects, which is a very important part of the interface to any class).
Side-effect-freeness would be a more interesting thing to be able to
specify than no modifications to static class data.
--
-- Joe Buck <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
Anagrams for "information superhighway": Enormous hairy pig with fan
A rough whimper of insanity
---
[ 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:
<47ec84$t43@hermes.synopsys.com>Path:
arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!MattReferences:
<4733v8$278@stellar.comnet.com> <u9n3ainrii.fsf@yorick.cygnus.com> <BASHFORD.95Oct31105612@toad.scripps.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt From: jbuck@Synopsys.COM (Joe Buck) Newsgroups: comp.std.c++ Subject: Re: class member: static name const; Legal? Date: 04 Nov 1995 09:39:01 GMT Organization: Synopsys Inc., Mountain View, CA 94043-4033 Approved: Matt@Austern Message-ID: <47ec84$t43@hermes.synopsys.com> References: <4733v8$278@stellar.comnet.com> <u9n3ainrii.fsf@yorick.cygnus.com> <BASHFORD.95Oct31105612@toad.scripps.edu> NNTP-Posting-Host: austern.hip.berkeley.edu