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. Advertisements

  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. Advertisements

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,656
    Chris Riesbeck
    Sep 2, 2004
  2. Dirk Schumann

    Cannot draw on mutable image

    Dirk Schumann, Dec 27, 2004, in forum: Java
    Replies:
    0
    Views:
    541
    Dirk Schumann
    Dec 27, 2004
  3. Replies:
    31
    Views:
    1,352
    Ingo R. Homann
    Aug 16, 2005
  4. hiwa
    Replies:
    4
    Views:
    729
    Oliver Wong
    Mar 8, 2006
  5. Thomas Matthews

    [C++] Mutable member functions?

    Thomas Matthews, Jan 11, 2004, in forum: C++
    Replies:
    3
    Views:
    11,462
    Josh Sebastian
    Jan 11, 2004
  6. Adam H. Peterson

    mutable base class

    Adam H. Peterson, Apr 2, 2004, in forum: C++
    Replies:
    5
    Views:
    690
    Adam H. Peterson
    Apr 3, 2004
  7. Replies:
    6
    Views:
    765
    Peter Otten
    May 10, 2007
  8. Hamilton, William

    RE: keyword checker - keyword.kwlist

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