Question: Involving Classes

I really hate to be bothersome with questions, but you guys really seem like nice and helpful people. :) I plan on making a base player class. That class will have sub-classes like Warrior, Wizard, . .and so on. My question is: How are files linked in c++? I am still very new at programming and this is something that is kinda fun for me and I am learning a lot by messing around with it. I just haven't figured out how to get my sub-classes to call my player class. I hope I have explained well what I am asking...sorry for the long winded rant :/.
I think you are looking for inheritance ... read a little about it :)
1
2
3
4
5
6
7
8
class Player {

};

class Warrior: public Player {   //class warrior inherits class player


};
Typically each class will have its own pair of .h/.cpp files. IE, you'd put the Player class in player.h and the Warrior class in warrior.h, and put their respective function bodies in player.cpp and warrior.cpp


Obligatory link: http://cplusplus.com/forum/articles/10627/


Okay so it will pick up on it the file as long as I put the header file no matter where it is on the computer? (Sorry if that's a stupid question)
Not quite.

In order to use your Player class, you'd need to do two things:

1) #include "player.h" in whatever cpp files use the Player class

2) Compile the player.cpp file and link to it.

If you're using an IDE like Visual Studio or Code::Blocks or whatever, #2 is accomplished just by having player.cpp as part of your project.
Usually your compiler needs to be able to find the header in a predefined directory; each compiler/IDE has different ways of doing it.
Topic archived. No new replies allowed.