Mutable keyword

Discussion in 'C++' started by Let_Me_Be, Dec 25, 2006.

  1. Let_Me_Be

    Let_Me_Be Guest

    Hi,

    I'm kinda worndering how the mutable keyword works.

    Because of speed, I added value caching into my base class, and the
    only posible way to implement this seemed to be adding the mutable
    keyword to cache representing members.

    The thing is, how will the program behave when the mutable members are
    modified in a const class variable. Will they change? Will they change
    only localy?

    Or is there another way to walk around the mutable keyword? Because
    non-mutable cache members dissalow me to use the class on right side of
    any operator.

    Thx for any hints...
     
    Let_Me_Be, Dec 25, 2006
    #1
    1. Advertising

  2. Let_Me_Be

    Rolf Magnus Guest

    Let_Me_Be wrote:

    > Hi,
    >
    > I'm kinda worndering how the mutable keyword works.
    >
    > Because of speed, I added value caching into my base class, and the
    > only posible way to implement this seemed to be adding the mutable
    > keyword to cache representing members.
    >
    > The thing is, how will the program behave when the mutable members are
    > modified in a const class variable. Will they change?


    Yes

    > Will they change only localy?


    Not sure what you mean here.

    > Or is there another way to walk around the mutable keyword?


    Well, the situation you describe is just what the mutable keyword is there
    for. If you really want to avoid it, you can allocate your cache with 'new'
    and let your object carry a pointer to it. If the pointer is const, you can
    still modify what it points to (as long as it points to non-const of
    course).
     
    Rolf Magnus, Dec 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Armhold
    Replies:
    1
    Views:
    1,457
    Chris Riesbeck
    Sep 2, 2004
  2. Dirk Schumann

    Cannot draw on mutable image

    Dirk Schumann, Dec 27, 2004, in forum: Java
    Replies:
    0
    Views:
    427
    Dirk Schumann
    Dec 27, 2004
  3. Replies:
    31
    Views:
    1,113
    Ingo R. Homann
    Aug 16, 2005
  4. Replies:
    6
    Views:
    457
    Peter Otten
    May 10, 2007
  5. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    355
Loading...

Share This Page