F
Fred
Hello
As mentioned in another post, I'm in the process of extending an existing
class.
One of the things I'm trying to achieve is an improvement in performance
through the use of some image caching. This means that the class itself can
serve up a scaled version of itself and use some basic caching to avoid
having to perform the scaling when the same scale value is used in
successive calls.
However there are many occasion in the code where only a const version of
the object is used - the intent being that the basic data defining the
object should not be changed. In these cases it should still be ok to change
any derived data - e.g. a cached scaled image. My question is: what is the
correct/best way of handling this.
At present I'm doing a const_cast but I always feel guilty doing this since
I feel like I'm undoing the good work of using consts in the first place.
Surely there must be a better way?
Thanks Fred
As mentioned in another post, I'm in the process of extending an existing
class.
One of the things I'm trying to achieve is an improvement in performance
through the use of some image caching. This means that the class itself can
serve up a scaled version of itself and use some basic caching to avoid
having to perform the scaling when the same scale value is used in
successive calls.
However there are many occasion in the code where only a const version of
the object is used - the intent being that the basic data defining the
object should not be changed. In these cases it should still be ok to change
any derived data - e.g. a cached scaled image. My question is: what is the
correct/best way of handling this.
At present I'm doing a const_cast but I always feel guilty doing this since
I feel like I'm undoing the good work of using consts in the first place.
Surely there must be a better way?
Thanks Fred