Newsgroups: comp.std.c++ Path: utzoo!censor!geac!alias!news From: Reid Ellis Subject: Re: Responses to ~const 1.6: Alternatives to ~const Message-ID: <1991Mar1.094159.40@alias.uucp> Sender: Reid Ellis Reply-To: Reid Ellis Organization: Alias Research, Inc. Toronto ON Canada References: Distribution: comp Date: Fri, 1 Mar 91 09:41:59 GMT Tom Ngo writes: >.. you have to set up two classes which are 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