Kind of an odd way to just call the function. Why not call cube and square directly instead of through ptr?
Anyways, you're passing references so your modifying the integers that you pass. This generally isn't preferred but you can just reset the variable values: http://codepad.org/k04mdR5F