Class Vectors
James Stanley

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:
game.cpp:

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:
If you need more info, ask and I can post it.

EDIT2:
Whilst I'm here, is it possible to change the colours on the file select dialog?

CGamesPlay

You need to include the header file with the player class in it in main.h.

gui_fg_color, gui_bg_color

James Stanley

Yeah, I have, I thought that went without saying...

Thanks for the gui stuff though

HoHo

Have you tried to put std::vector instead of plain vector in header?

James Stanley

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
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).

James Stanley

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.

Thread #586024. Printed from Allegro.cc