Afficher un message
Vieux 01/07/2008, 16h39   #2
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Use const_cast to modify member variable?

Immortal Nephi wrote:

> How can I modify member variable inside class if member function has
> const like mem_Func(void) const. Please do not offer the keyword --
> mutable.


Why not? It's meant to be used for member variables that do not affect
logical constness. If the member variable you are modifying better not be
declared mutable, you probably shouldn't be modifying it in a const member
function.

> I want to know if keyword -- const_cast can be done.


Yes it can be used to cast away constness, but it will produce undefined
behavior if you use it on an object declared const.

> If mutable is only the solution, I will follow not to use const_cast.


What is the underlying problem that you are trying to solve? I looks as
though you might be headed the wrong direction, and in order to give better
advice some additional information about the background would be good.


Best

Kai-Uwe Bux
  Réponse avec citation
 
Page generated in 0,05029 seconds with 9 queries