I have two classes in my code: CoinManager, which has one function only, which is to add a specific amount of coins to a specific Player object, and the Player class.
class Player{
public:
void addCoins(int amount){
coins+=amount;
}
int getCoins(){
return coins;
}
private:
int coins = 0;
}
class CoinManager{
public:
void freeCoins(Player user, int amount){
user.addCoins(amount);
}
}
int main(){
Player i;
CoinManager CM;
i.addCoins(20); //this works
CM.freeCoins(i, 20); //this doesn't work
}
With the CoinManager class I can have a getter function of Player's coins like this:
int getCoins(Player user){
return user.getCoins();
}
But I cannot use the freeCoins(Player i, int amount); function. No error comes up, simply the function does not change the value of coins in the Player object.