error LNK2001

Hello

I have these 2 classes, all classes are in the same header...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class player
{
	class moveit;
public:

	player():pcolor(-2){};
	~player();

	int pcolor;		// player's color
	 stone p_stone[12];  //didnt mention class 'stone'
	 stone eat_move_p[12];

	static void update_stone(int &i, int &j,int &count, int a);		//updates stone
	moveit *pmove;
	

};

class checker
{
public:
	checker();
	~checker();
	static int board[8][8];
	static player *black;
	static player *white;
	static int player_turn;
	bool check_to_eat(int a[8][8],int player_t);
	void print_board(int board[8][8]);
private:
	
	int static const black_count=12;
	int static const white_count=12;


};


This function is declared in player.h , and i want to use the 'player' objects that are declared in checker.h,but I get:

"error LNK2001: unresolved external symbol "public: static class player * checker::white"

error LNK2001: unresolved external symbol "public: static class player * checker::black"

here is the fucntion:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void player::update_stone(int &i,int& j ,int & count, int a)		// updates arrays of stones
				
{
	if(a==0)
		{
			
			checker::black->p_stone[count].i=i;   //HERE
			checker::black->p_stone[count].j=j;   //HERE
			
		}

	if(a==1)
		{
			checker::white->p_stone[count].i=i;   //HERE
			checker::white->p_stone[count].j=j;   //HERE
		}
	count++;
};


I don't understand what to do and why it's happening...

please help !!
Thank you
When you declare static class members you have to actually create them in some source file. For example in checker.cpp put
1
2
player *checker::black = 0; // Better initializing them too
player *checker::white = 0;

Do that for every static variable you have.
Class declarations don't reserve memory for their members.
Last edited on
Where is checker instantiated? In order for black and white to be defined, checker must be instantiated somewhere.
Thank you !!! :D
Topic archived. No new replies allowed.