Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Class Vectors

This thread is locked; no one can reply to it. rss feed Print
Class Vectors
James Stanley
Member #7,275
May 2006
avatar

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
Member #2,559
July 2002
avatar

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

gui_fg_color, gui_bg_color

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

James Stanley
Member #7,275
May 2006
avatar

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

Thanks for the gui stuff though

HoHo
Member #4,534
April 2004
avatar

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

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

James Stanley
Member #7,275
May 2006
avatar

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
avatar

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

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

James Stanley
Member #7,275
May 2006
avatar

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.

Go to: