Mutable keyword

L

Let_Me_Be

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

Rolf Magnus

Let_Me_Be said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top