Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7695
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: mutable v's non const |
| Date | 2011-07-10 21:16 +1200 |
| Message-ID | <97t90qFpbuU1@mid.individual.net> (permalink) |
| References | <A00Sp.5482$Zm3.103@newsfe11.ams2> <ivb9mo$grv$1@dont-email.me> <lRdSp.28808$Ll1.18268@newsfe24.ams2> |
On 07/10/11 08:58 PM, Paul wrote:
>
> "red floyd"<no.spam.here@its.invalid> wrote in message
> news:ivb9mo$grv$1@dont-email.me...
>> On 7/9/2011 10:15 AM, Paul wrote:
>>> Hi groupies.
>>>
>>> What is the meaning of the "mutable" word in C++ circles?
>>> Mutable apparently means "it can change". So why are the terms "mutable"
>>> and "non-mutable" used instead of const and non-const and in what way
>>> are they different?
>>
>> A mutable class member may be modified even if the object is const.
>>
>> e.g.:
>>
>> class Example {
>> public:
>> void good() const {
>> mutable_int = 7;
>> }
>> void bad() const {
>> non_mutable_int = 7; // ERROR
>> }
>> Example() :
>> mutable_int(0), non_mutable_int(0)
>> {
>> }
>> private:
>> mutable int mutable_int;
>> int non_mutable_int;
>> };
>>
> Thanks for the example.
>
> Why would you make such a function const in the first place?
> If its not const why mark it as const?
So it can be called on a const instance of an Example.
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-09 18:15 +0100
Re: mutable v's non const red floyd <no.spam.here@its.invalid> - 2011-07-09 21:26 -0700
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 09:58 +0100
Re: mutable v's non const Ian Collins <ian-news@hotmail.com> - 2011-07-10 21:16 +1200
Re: mutable v's non const Daniel Weber <usenet@daniel-weber.eu> - 2011-07-10 12:41 +0200
Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-10 14:01 +0100
Re: mutable v's non const Miles Bader <miles@gnu.org> - 2011-07-10 23:35 +0900
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:15 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:12 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 16:21 +0100
Re: mutable v's non const Werner Erasmus <werasm@gmail.com> - 2011-07-10 21:55 +0200
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 21:45 +0100
Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-10 22:03 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-10 23:37 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 17:43 +0100
Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-11 17:48 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 18:04 +0100
Re: mutable v's non const Leigh Johnston <leigh@i42.co.uk> - 2011-07-11 18:14 +0100
Re: mutable v's non const "Paul" <pchristor@yahoo.co.uk> - 2011-07-11 18:32 +0100
Re: mutable v's non const Oliver Jackson <chexmofo@hotmail.com> - 2011-07-12 12:32 -0700
Re: mutable v's non const "io_x" <a@b.c.invalid> - 2011-07-12 09:42 +0200
Re: mutable v's non const Werner Erasmus <werasm@gmail.com> - 2011-07-10 17:17 +0200
Re: mutable v's non const Juha Nieminen <nospam@thanks.invalid> - 2011-07-12 06:04 +0000
Re: mutable v's non const "MikeP" <mp011011@some.org> - 2011-07-15 00:50 -0500
csiph-web