Hello Cheddar99,
To start with line 9 of the ".cpp" file should look like line 4
cPlayer::setScore(int points)
and the same for the function on line 13. These functions are part of the class. As you have written them they are regular function that do not have access to the "private" class variable.
In the future posting an error message like
... error: 'score' was not declared in this scope
has no meaning because it does not mention the file it is in or the line number it is for. In this case it is easy to fine, but not all the time. In the future post the complete error message that the compiler put out.
But I don't understand why, when score is already declared in the header file. |
"scope may be defined in the class, but you need class member functions to access the "private" variables. In the class the forward declaration ,(or prototype),
void setScore(int);
does not mean that you can write the function as you have. A ".cpp" file like your "cPlayer.cpp" is where you put the member functions of the class and all member functions should look like your ctor with what follows the "::" being the function name.
A quick note: a regular variable should start with a lower case letter. A variable defined as a constant would be in all capital letters. And a class or a struct should start with a capital letter. Not sure if this is a written rule, but it is the generally accepted way of naming.
I believe that when you add
cPlayer::
to the beginning of "setScore" and "getScore" it should clear up the problem.
Hope that helps,
Andy