Wednesday 24 November 2010

error C2662: cannot convert 'this' pointer from 'const

error C2662: cannot convert 'this' pointer from 'const

OK I've fallen for this one too many times now! What is means is that you are calling a function on a const object, and the compiler is worried that the function will modify the object.. so assuming it doesnt then add const to the end of the declaration and all will be well in the world again.

class MyClass
{
void Func() const;
}