Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rutgers!att!cbnewsl!dog From: dog@cbnewsl.ATT.COM (edward.n.schiebel) Newsgroups: comp.lang.c++ Subject: Re: const and caching Message-ID: <3053@cbnewsl.ATT.COM> Date: 28 Nov 89 20:15:05 GMT References: <4289@cadillac.CAD.MCC.COM> Organization: AT&T Bell Laboratories Lines: 26 From article <4289@cadillac.CAD.MCC.COM>, by vaughan@puma.cad.mcc.com (Paul Vaughan): > > Consider the method A::foo(), where foo() conceptually does > not change any aspect of the A object, but does cause some information > to be cached, so that the next time A::foo() is called, it will return > (the same result) sooner. I have the same problem with const. I view it as "constant from the outside" while the language (currently ? :-) considers it as "constant through and through and no data may change". The way I have gotten around it is to cast away constness on this. e.g.: void A::foo() const { // change some cached value (foo*)this->cached_value = new_value; } This works as long as the compiler didn't decide to put your A into some deluxe read only memory, in which case the results are undefined. For my money, I think this is a reasonable compromise. Ed Schiebel AT&T Bell Laboratories dog@vilya.att.com