Thread View: comp.std.c++
10 messages
10 total messages
Started by Bret Pehrson
Tue, 31 Oct 1995 02:41
class member: static name const; Legal?
Author: Bret Pehrson
Date: Tue, 31 Oct 1995 02:41
Date: Tue, 31 Oct 1995 02:41
20 lines
1113 bytes
1113 bytes
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.
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. ]
Re: class member: static name const; Legal?
Author: Jason Merrill
Date: Tue, 31 Oct 1995 05:54
Date: Tue, 31 Oct 1995 05:54
17 lines
1148 bytes
1148 bytes
>>>>> 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. ]
Re: class member: static name const; Legal?
Author: bs
Date: Tue, 31 Oct 1995 16:30
Date: Tue, 31 Oct 1995 16:30
33 lines
1692 bytes
1692 bytes
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. ]
Re: class member: static name const; Legal?
Author: Don &
Date: Tue, 31 Oct 1995 19:28
Date: Tue, 31 Oct 1995 19:28
24 lines
1739 bytes
1739 bytes
>>>>> "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. ]
Re: class member: static name const; Legal?
Author: Jason Merrill
Date: Tue, 31 Oct 1995 22:32
Date: Tue, 31 Oct 1995 22:32
18 lines
1640 bytes
1640 bytes
>>>>> 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. 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. ]
Re: class member: static name const; Legal?
Author: Ken Walter
Date: Wed, 01 Nov 1995 22:02
Date: Wed, 01 Nov 1995 22:02
35 lines
2169 bytes
2169 bytes
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. ]
Re: class member: static name const; Legal?
Author: Jason Merrill
Date: Wed, 01 Nov 1995 23:50
Date: Wed, 01 Nov 1995 23:50
15 lines
1263 bytes
1263 bytes
>>>>> 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. ]
Re: class member: static name const; Legal?
Author: Colin Jensen
Date: Wed, 01 Nov 1995 23:58
Date: Wed, 01 Nov 1995 23:58
22 lines
1238 bytes
1238 bytes
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. ]
Re: class member: static name const; Legal?
Author: Ralph Shnelvar
Date: Thu, 02 Nov 1995 23:28
Date: Thu, 02 Nov 1995 23:28
25 lines
1437 bytes
1437 bytes
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. ]
Re: class member: static name const; Legal?
Author: 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. ]
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