Topic: class member: static name const; Legal?
Author: solution@gate.net (Ken Walter)
Date: 1995/11/01 Raw View
In message <u9loq1nv8z.fsf@yorick.cygnus.com> - jason@cygnus.com
(Jason Merrill) writes:
:>
:>>>>>> Don & <bashford@scripps.edu> 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.
:>
:>A more general facility is a way to specify that a particular function has
:>no side effects; distinguishing static data members from other global data
:>for this purpose seems pointless. Many compilers (C as well as C++)
:>provide this as an extension, but I don't see any chance of it being
:>standardized.
Why wouldn't it mean that it doesn't modify any of the static data members?
Ken Walter
* All the above is hearsay and the opinion of nobody in particular
Microsoft Network, or any service owned in full or in part by Microsoft, is
prohibited from redistributing this work in any form, in whole or in part.
Copyright, Kenneth G. Walter, 1995. License to distribute this post is
available to Microsoft for $1,000 US per instance.
Posting without permission constitutes an agreement to these terms. Please
send notices of violation to solution@gate.net and postmaster@microsoft.com
---
[ 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. ]
Author: jason@cygnus.com (Jason Merrill)
Date: 1995/11/01 Raw View
>>>>> Ralph Shnelvar <ralphs@tesser.com> writes:
> So is there a way to indicate that a static member function will not
> modify other static members of the class. I think that is what Bret
> would like to do.
> So would I.
Why?
Jason
---
[ 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. ]
Author: Colin Jensen <cj@accom.com>
Date: 1995/11/01 Raw View
In article <BASHFORD.95Oct31105612@toad.scripps.edu> bashford@scripps.edu (Don Bashford) 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.
I think perhaps you think that const member functions cannot modify
static data. They can.
The following is permitted:
class A {
static int a;
public:
void g () const { a++; }
};
---
[ 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. ]
Author: ralphs@tesser.com (Ralph Shnelvar)
Date: 1995/11/02 Raw View
jason@cygnus.com (Jason Merrill) wrote:
>>>>>> Ralph Shnelvar <ralphs@tesser.com> writes:
>
>> So is there a way to indicate that a static member function will not
>> modify other static members of the class. I think that is what Bret
>> would like to do.
>
>> So would I.
>
>Why?
>
So that my particular static member function doesn't modify my static
members.
Why is this difficult to understand? I'm not flaming you, it is just
that others here seem to think this is a silly thing to want to do and
I don't see -that-.
Ralph
---
[ 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. ]
Author: bs@research.att.com
Date: 1995/10/31 Raw View
Bret Pehrson <BretP@strata3d.com> writes:
> Is the following legal?
>
> class base
> {
> static funkie(void) const;
> };
>
> I spend 20 minutes reading the grammar and could not figure it out. In
> any case, my compiler complains if I mix static and const for the same
> member function.
>
> I presume that it is legal and my compiler is crap, however I would
> rather hear that from a C++ language expert.
Think of it this way: `static' means that the member isn't associated with
any particular object of the class, it has no `this' pointer. `const' means
that the member may not modify the state of the object it is invoked for,
its `this' pointer is a pointer to const. The two notions doesn't mix and
your example is illegal.
The example is outlawed by a semantic constraint, not by a grammar rule
(in other words, it is an issue of meaning, rather than syntax).
- Bjarne
> Tnx.
---
[ 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. ]
Author: bashford@scripps.edu (Don &)
Date: 1995/10/31 Raw View
>>>>> "Jason" == Jason Merrill <jason@cygnus.com> writes:
In article <u9n3ainrii.fsf@yorick.cygnus.com> jason@cygnus.com (Jason Merrill) writes:
>>>>> Bret Pehrson <BretP@strata3d.com> writes:
>> Is the following legal?
>> class base { static funkie(void) const; };
Jason> Nope; the 'const' qualifier affects the 'this' parameter to
Jason> a member function, so applying it to a static member
Jason> function is meaningless.
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.
Don Bashford
bashford@scripps.edu
[ 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. ]
Author: jason@cygnus.com (Jason Merrill)
Date: 1995/10/31 Raw View
>>>>> Bret Pehrson <BretP@strata3d.com> writes:
> Is the following legal?
> class base
> {
> static funkie(void) const;
> };
Nope; the 'const' qualifier affects the 'this' parameter to a member
function, so applying it to a static member function is meaningless.
Jason
---
[ 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. ]