For some reason (and I would really like to know exactly what that reason is ;)) my ++ operator overloading via a a friend function does not want to return the modified object back to the application.
Ok some code, first is the interface:
friend Player operator ++(const Player & p);
and the implementation:
1 2 3 4 5 6 7 8 9 10
Player operator ++(const Player & p)
{
Player tempPlayer(p.name, p.team, p.level, p.points);
tempPlayer.points = p.points + 1;
if (tempPlayer.points % 100 == 0)
tempPlayer.level = p.level + 1;
return tempPlayer;
}
and i am calling it with a:
++ThePlayer
from inside main.cpp.
When I display all my member info before the call to ++ and then display all after the call they are the same...
Well, you aren't modifying the object the operator is called for, so it isn't surprising that nothing changes.
You're returning a temporary object (which you should only do for postfix ++), but you're not using it.
Thanks Athar, I see what you mean. In mine the lack of the & after Player is responsible for a copy of the object being made right? Implemented your advice.