Hello, I am having this problem which keeps reoccurring during programming.
In a class, for example, FloatArray I want to make a function
that to the user, doesn't change the class, but the function might actually change private parts of the object, to make it more efficient.Code:float average(int from, int to);
In this case, I want to save a list of the last 10 averages that user calculated, so that if the user asks for the same average, it wont need to be recalculated.
The problem is that I can't make average() const, because it changes a (hidden) list inside of the object. Is there any way to use const and keep the benefits of const in this case?
Whenever I have this problem, I usually just give up on const and that recursively forces me to make everything non-const. What should I do?
Thanks for the help!