Incrementing/Decrementing Object's hitpoints using classes

This is a discussion on Incrementing/Decrementing Object's hitpoints using classes within the C++ Programming forums, part of the General Programming Boards category; I can't seem to increment/decrement an object's hitpoints in a game. For example...
Code:
#include <iostream>
class Player
{
public:
...

Isn't assigning anything to your class. It's calling the method getHitPoints and getting the value 10 or whatever and then decrementing 2 from that and displaying it. To actually change it you need to call the method for setting the hitpoints in your class. As it has already been stated, something like

Code:

Bob.setHitPoints(Bob.getHitPoints() - 2);

You could also make setHitPoints return an int that is the new health value if you wanted to.

"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Having things like GetHP() and SetHP() is not really a very good OOP way of doing things. Your way offers almost no benefit over a struct; you aren't hiding the data or improving access to it, you're only obfuscating access to it.

A good way for your class is to do this:

1) Have a constructor which sets the character's max HP, and sets the current HP to max.

2) Have two functions -- Heal() and Harm(). Heal() increments the HP, Harm() decrements. Both of them do bounds checking (i.e. you can never get above max HP or below 0)

3) Have an isDead() function that tells if the current HP is positive.

4) Have a HP() function to get the current HP, but do NOT allow a direct set of HP.