Please see my comment — did you get it? The problem is quite apparent: C++ does not allow implicit cast from non-constant pointer to a constant one. Such cast would imply that the object pointed by the constant pointer cannot change, but in fact, it can, as it is also pointed by the non-constant pointer used as a source pointer in your assignment operation.
As a work-around, C++ reserves the
const_cast<>
operator. Please see:
http://msdn.microsoft.com/en-us/library/bz6at95h%28v=vs.100%29.aspx[
^],
http://www.cplusplus.com/doc/tutorial/typecasting/[
^].
You should use it with great care and preferably avoid using it, if you can obtain a constant pointer in first place (the source of assignment, right-part of assignment), or use a non-constant pointer as the left part of assignment (target of assignment). If you still need to use the
const_cast<>
operator, you should be sure that the object pointed by both pointers cannot actually be modified, otherwise such modification can give unpredictable result. See also this discussion:
http://www.cplusplus.com/forum/general/17155/[
^].
—SA