Classes and Instances
Hey, I'm sorta of a long time member here at MPGH, but aside from that I'm really trying to get into CPP. I've found a good book somewhat to help me understand C++, it uses players in a game, etc. I'm a beginner in C++ and trying to understand the basics really well before I go onto anything else.
In the code there's this:
later on it has this piece of code in it, which I'm confused about:
Why not just add this:
Because with function "Player::getTreasure" would just mean that all players get treasure. Could anyone explain this to me?
Also, the website I found that all on and link below is the chapters:
online C++ tutorial: Using a Class (Instantiation)ⓘ
In the code there's this:
Code:
Player blueHat; Player redHat; Player greenHat; Player yellowHat;
Code:
void Player::getTreasure() {
health++; // increments the value of the player's health by one
}
Code:
void Player.greenHat::getTreasure() {
health++; // increments the value of the player's health by one
}
Also, the website I found that all on and link below is the chapters:
online C++ tutorial: Using a Class (Instantiation)ⓘ

