Using Functions With Classes

Im trying to make a somewhat simple RPG. I am wondering if the functions that affect my Class Player should be type Player, type void or some other type. Should i be using pointers or making my functions type Player.

Here is an example of a simple levelUp function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Player
{
Public:
     Player levelUp(Player a);      //The function declaration

Private:
     int Hp;
     int Att;
     int Def;
     int Speed;
}

 Player Player::levelUp(Player a)  //The function definition
{
	a.Hp =+ 3;
	a.Att =+ 2;
	a.Def =+ 2;
	a.Speed =+ 2;
	
	return a;
	
}


Is this how i should be using functions that affect my Player class or should i be using pointers/references?
Why are you passing a Player object to your levelUp function?
Also, why is it returning a Player object? I fail to see the logic.

Why not void?

1
2
3
4
5
6
void Player::levelUp() {
	hp+=3;
	att+=2;
	def+=2;
	speed+=2;
}
Topic archived. No new replies allowed.