Article View: comp.std.c++
Article #881Re: Responses to ~const 1.6: Alternatives to ~const
From: Reid Ellis
Date: Fri, 01 Mar 1991 09:41
Date: Fri, 01 Mar 1991 09:41
32 lines
1348 bytes
1348 bytes
Tom Ngo <ngo@tammy.harvard.edu> writes:
>.. you have to set up two classes which are <identical in all
>respects except that in one, all members are non-const, and in the
>other, all data members are const except the ones that you want to
>behave as if they were ~const.
...
>Are there any other alternatives?
How about this?
struct foo {
foo();
int method() const;
int sometimes() const;
int nonconst();
private:
foo & fRef;
};
foo::foo() : fRef(*this) {}
Then, if say "sometimes()" needs to do a non-const thing, it can
simply say "fRef.nonconst()".
I guess this is esentially casting the const away, but the compiler
won't make a peep about it.
Reid
--
Reid Ellis 176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada
rae@utcs.toronto.edu || rae%alias@csri.toronto.edu
CDA0610@applelink.apple.com || +1 416 446 1644
Technical Details
Message-ID:
<1991Mar1.094159.40@alias.uucp>Path:
arc1-ca.pugleaf.net!utzoo!censor!geac!alias!newsReferences:
<NGO.91Feb19113232@tammy.harvard.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!utzoo!censor!geac!alias!news From: Reid Ellis <rae@utcs.toronto.edu> Subject: Re: Responses to ~const 1.6: Alternatives to ~const Message-ID: <1991Mar1.094159.40@alias.uucp> Sender: Reid Ellis <rae%alias@csri.toronto.edu> Reply-To: Reid Ellis <rae@utcs.toronto.edu> Organization: Alias Research, Inc. Toronto ON Canada References: <NGO.91Feb19113232@tammy.harvard.edu> Distribution: comp Date: Fri, 1 Mar 91 09:41:59 GMT