So, I've got a class that, when only using an instance of it to read relavent data, I pass a const reference to whatever function uses it. However, the "read only" member function actually writes to the class... so how can I implement the following, and allow const correctness? MUST I used a const_cast? I shy away from this. I thought about just making LastX and LastY static... but that would render this thing not very multithreaded friendly...
Maybe the flaw is in what I am doing?
class IAmUseful {
public:
int *CalcAPointer(int X, int Y) const {
if (LastX_ != X || LastY != Y) {
LastX_ = X;
LastY_ = Y;
LastPointer_ = SomeStuffBasedOnXAndY;
}
return LastPointer_;
}
private:
int LastX_, LastY_
int *LastPointer_;
};
--------
// At some point in the code that uses it
void ThisUsesIt(const IAmUseful &UsefulObj, int A, int B) {
int *NewPointer = UsefulObj.CalcAPointer(A, B);
// Doesn't matter what I do here because we now have const problems.
// Not to mention the class probably wouldn't compile either huh?
}
Cheers
-Scott