static class variable problem..

Hey everyone,

I'm having issues with static class variables..

Here is my source..

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
  class Ground {

	protected:
	
	//Amount of ground blox
	static unsigned int amount;
	
        ...

	public:

	//Constructor/Destructor
	Ground (float newXPos, float newYPos, float newXSize, float newYSize);
	//~Ground();	

        ...

};

Ground::Ground (float newXPos, float newYPos, float newXSize, float newYSize) {

	//Up the amount of thingers
	amount++;

        ...

}
  


I get the error..

undefined reference to `Ground::amount'


Im probably just overlooking something.. but yeah thanks for any help
Last edited on
closed account (3hM2Nwbp)
Outside of your class declaration, you'll need to put in:

 
unsigned int Ground::amount = 0; // or whatever you want it to be. 


The problem that the linker has with your code is that you've declared the static member, but never defined it.
Last edited on
ok sweet thanks
Topic archived. No new replies allowed.