|
Class Vectors |
James Stanley
Member #7,275
May 2006
|
OK, I am using a vector to store information about my characters and currently, for me, it is not possible to access the vector from another source file. How would I go about that? I've tried extern vector in the header, but it wouldn't compile. Secondly, I can't access the Class outside the source file. This is the code so far: main.cpp: //Some variables player *local_player; //Compiles fine //More variables main.h: //Some variables extern player *local_player; //main.h:44: error: expected initializer before '*' token //More variables
If I don't have the declaration in the header: void init_game(void) { //some stuff local_player = new player(1000 /*player x*/, 1000 /*player x*/, 1 /*player d*/, name, img_ship[1]); //game.cpp:11: error: 'local_player' was not declared in this scope players.push_back(local_player); //game.cpp:12: error: 'players' was not declared in this scope //some more stuff Also note, the thing about 'players' not being declared. That's because I can't extern the vector. EDIT: EDIT2: |
CGamesPlay
Member #2,559
July 2002
|
You need to include the header file with the player class in it in main.h. -- Ryan Patterson - <http://cgamesplay.com/> |
James Stanley
Member #7,275
May 2006
|
Yeah, I have, I thought that went without saying... Thanks for the gui stuff though |
HoHo
Member #4,534
April 2004
|
Have you tried to put std::vector instead of plain vector in header? __________ |
James Stanley
Member #7,275
May 2006
|
I know it's bad practice, but I'm 'using namespace std', so I don't think I need to. I'll go try |
CGamesPlay
Member #2,559
July 2002
|
Quote: main.h:44: error: expected initializer before '*' token This means that the type 'player' is not defined. Either you have other compile errors you need to work out first (see Hoho's post), or you haven't declared the class at all (i.e. not included the header). -- Ryan Patterson - <http://cgamesplay.com/> |
James Stanley
Member #7,275
May 2006
|
Alright, it'll probably be in the other errors then, but I think they're caused by it... Anyway, I got to have tea now, be back later. |
|