My codes below, i'm basically trying to get my head around inheritance and classes, and objects.
so i was hoping to create two types of 'player'. and then be able to call functions which show the differences in .. the players basically haha
but for some reason this isn't working.
On my 'class Warrior' line, i get the error "return type may not be specified on constructor"
and in my main.cpp
my Mage.displayStats();
says it's inaccessible.
You have displayStats() as a member function of your player class but what you have actually implemented is an ordinary function which will have global scope. You need to use the scope resolution operator to tell the compiler your are implementing a member function.
1 2 3 4 5
voidplayer::displayStats(){
.
.
.
}
Now once you are inside the function you are inside the player class scope and you can use the other member variables directly:
cout << magic << endl;
This is equivalent to using the this pointer (which isn't necessary here):
cout << this->magic << endl;
Similarly for the other output lines.
Also, putting usingnamespace std in a header file pulls in the entire std namespace and hence every time you #include "player.h" the entire std namespace comes along for the ride. Eventually this will lead to a conflict of names of identifiers. In the header file it is best to leave out the using statement and fully qualify the names, i.e., std::string, std::cout, std::endl.
That's excellent!
thank you for the detailed explanation, it really explains a lot!
I see were i was going wrong now
and thank you for letting me know about the headers, very good to know :)