By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,128 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,128 IT Pros & Developers. It's quick & easy.

Mutable keyword

P: n/a
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...

Dec 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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).
Dec 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.