First of all a few coding habits you should stick to:
1) If a field in a class (i.e.: private/protected/public) is not used omit it, for example on line 94 the private keyword can be removed.
2) Try to avoid get and set methods like the plague, because you can break encapsulation without realizing it like you did in the code above. for example all of these:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
string& getPlayerName() {
return name;
}
string& getPlayerClassName() {
return classname;
}
int& getPlayerStats0() {
return stats[0];
}
int& getPlayerStats1() {
return stats[1];
}
int& getPlayerStats2() {
return stats[2];
}
|
if someone will type
getPlayerStats2() = 5;
than stats[2] will now be equal to 5 which breaks the purpose of the private section as it can be easily changed by anyone from the outside and in this case is equal to just making all of your private members public.
3) from the same example of point 2 when returning a built in value prefer to return by value, in your case
int
and not
int&
for example or
const int&
so that the private section cant be changed.
4) always divide your code into .cpp and .h files (an exception being templated classes)
i would recommend you learn from :
http://www.learncpp.com/ as it is beginner friendly and explains everything in depth.
By the way i have some free time atm so i'l write a commented fix to your code so you can use it as a reference to future code. I will post it shortly.
#EDIT:
5) use the array.h library insted of c arrays its much safer and has many useful features
6) Lastly the names must be easily understandable, in this case
cStats
and
pStats
are vague and when reading the code i cant figure out what each index of stats means up until the displayPlayer function which shows what each index means.
a better approach would be to make separate variables with descriptive names.