View Single Post
Old Jan 16th, 2006, 4:37 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
The reason for the error is that the argument to both functions is a const pointer, but you're attempting to copy it to a non-const pointer. Doing such a thing would provide a direct means of modifying a const object, and the compiler refuses.

The solution is to use a technique that does not (implicitly or explicitly) to remove the const'ness of the pointer. A poor solution (which, if the person marking your exercise is awake, would result in lower marks) would be to bludgeon the compiler into submission by using a typecast.

Is getNext() a const method of IntNode? If it is, you will not need to use a typecast. If it isn't, then whoever gave you the assignment should be shot as the only solution would be to use a typecast.

Are you allowed to use recursion?
grumpy is offline   Reply With Quote