loop inside const function

I am tryng to run a loop inside a member function:
double Polynom::valueAt (double dValue) const
{
result=0;
for (i=0;i<deg+2;i++)
{
result=result+(pow(coefs[i],i));
}
return result;
}

I am getting error:
Erroerror C2166: l-value specifies const object



I can't remove the const, any ideas how to do that?
Last edited on
You've not declared result or i
You not posted the declaration of coefs
You've not posted the full error (including the line)
You've not declared result or i


Well, this is a class code. It is quite possible that result and i are data members.

Anyways, the error I see is, that valueAt is a constant function and you are trying to modify a variable in a read only function which is not permitted.

http://msdn.microsoft.com/en-us/library/6ke686zh(VS.80).aspx
Yes, right, result and i are data members. I declared another varaibles inside the function, now it is working.
Thank you, guys, I learned something new today!!
Topic archived. No new replies allowed.