How to use an object in more than one header

now i have a game project, i need to modify the values stored in an array in more than one header, any ideas??

thanks in advance :)
What do you mean? Could you post some code?
I mean in a header file i created a class named Board that contains a 2-dim array named board, in my game i have some creatures moving on this board each has a letter to represent. If i define a header for each creature can i have a common Board object to modify through each of these headers??

This is a sample of function move for the worm from "worm.cpp", were co.x and co.y are the coordinates were the worm exists, here i created a Board object called mybrd,, can i access it through another header file (snake.h for example)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Worm::move(){
	srand(GetTickCount());
	mybrd.board[co.y][co.x]=' ';
	int r=rand()%4;
	if((r==0) && (mybrd.board[co.y][co.x-1]==' '))
		co.x--;
	else if((r==1) && (mybrd.board[co.y][co.x+1]==' '))
		co.x++;
	else if((r==2) && (mybrd.board[co.y-1][co.x]==' '))
		co.y--;
	else if((r==3) && (mybrd.board[co.y+1][co.x]==' '))
		co.y++;
	mybrd.board[co.y][co.x]=co.dis;
	agebreed++;
}


Last edited on
Could you please post the code where mybrd defined, and how the type of mybrd is defined.

Without looking at those, I suggest passing the board as a parameter (preferably as a reference to avoid copying), or setting it as a global variable (not recommended).

Also you should call srand() only once in your program.
I suggest polymorphism.
Topic archived. No new replies allowed.