Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7689

Re: mutable v's non const

From red floyd <no.spam.here@its.invalid>
Newsgroups comp.lang.c++
Subject Re: mutable v's non const
Date 2011-07-09 21:26 -0700
Organization A noiseless patient Spider
Message-ID <ivb9mo$grv$1@dont-email.me> (permalink)
References <A00Sp.5482$Zm3.103@newsfe11.ams2>

Show all headers | View raw


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;
};

Example::good() will compile, and is fine.
Example::bad() will not compile because it's modifying a
   non-mutable member of a const object.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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