problem with a function declared as const

I need an opinion on the way I solve the following problem:
CLASS_NAME contains an object CLASS2 named G2. That contains some large arrays, and some functions, that affects the value of the arrays contained.

I need to create an overload operator() for the class CLASS_NAME with the following structure:

double operator() (const column_vector& x) const

Since there is the final const, this function is not able to modify any element of the CLASS_NAME. And thus I cannot call any function in CLASS2 that is not declared as const.

To solve this problem I simply made a copy of the CLASS 2 object, and then I operate on this new object..

double CLASS_NAME::operator() (const column_vector& x) const
double res;
G3 = G2; 
res = G3.some_func();

In this way it works but I guess it is not much efficient, considering that G2 is quite big.

I would therefore ask if there is a better way to solve it. I cannot modify neither the CLASS_2 nor the operator() declaration.

Many thanks

If some_func() isn't const it shouldn't be used in const fucntion. Not "can not", but "should not". If it affects it's operand, you should either create new, const version alongside it, or use a copy of this object to manipulate it.
Topic archived. No new replies allowed.