Why SDL_Surface can not be static member in Class

Hi,

I have a problem, I'm a newbie to SDL and I've been making a simple class for controlling SDL so I wanted to make SDL_Surface * screen a static member in a class and my VC++ 9 Compiler reurns the following error:
1
2
1>SGEMain.obj : error LNK2001: unresolved external symbol "public: static struct SDL_Surface * cGame::screen" (?screen@cGame@@2PAUSDL_Surface@@A)
1>C:\Users\VITA\Documents\Visual Studio 2008\Projects\GameEngineSDL\Debug\GameEngineSDL.exe : fatal error LNK1120: 1 unresolved externals

Is it possible to make screen same for all objects that are declared in the calss here is the code of a calss:
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
class cGame
{
private:
	SDL_Event event;
public:
	static SDL_Surface * screen;

	cGame()
	{
		SDL_Init(SDL_INIT_EVERYTHING);
		screen = SDL_SetVideoMode(640,480,24,SDL_SWSURFACE);
	}

	cGame(int window_width,int window_height,int window_bpp,bool full_screen = false)
	{
		SDL_Init(SDL_INIT_EVERYTHING);
		if(full_screen == false)
			screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_SWSURFACE);
		else 
			screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_FULLSCREEN);
	}

	~cGame()
	{
		SDL_Quit();
	}

	void SetResolution(int window_width,int window_height,int window_bpp)
	{
		//SDL_Init(SDL_INIT_EVERYTHING);
		screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_SWSURFACE);
	}

	void UpdateScreen()
	{
		SDL_Flip(screen);
	}

	void SetCaption(char *caption)
	{
		SDL_WM_SetCaption(caption,NULL);
	}

	void SleepMiliSeconds(int miliseconds)
	{
		SDL_Delay(miliseconds);
	}

	void SleepSeconds(int seconds)
	{
		SDL_Delay(seconds * 1000);
	}

	int HandleEvents()
	{
		int key=NULL;
		if( SDL_PollEvent(&event) )
		{
			if( event.type == SDL_QUIT )
			{
				return -99; //QUIT
			}

			if( event.type == SDL_KEYUP )
			{
				switch( event.key.keysym.sym )
				{
				case SDLK_UP    : key =  -1; return key; break; //UP Arrow
				case SDLK_DOWN  : key =  -2; return key; break; //DOWN Arrow
				case SDLK_RIGHT : key =  -3; return key; break; //RIGHT Arrow
				case SDLK_LEFT  : key =  -4; return key; break; //LEFT Arrow
				case SDLK_RCTRL : key =  -5; return key; break; //CTRL
				case SDLK_LCTRL : key =  -5; return key; break; //CTRL
				case SDLK_RALT  : key =  -6; return key; break; //ALT
				case SDLK_LALT  : key =  -6; return key; break; //ALT
				case SDLK_RSHIFT: key =  -7; return key; break; //SHIFT
				case SDLK_LSHIFT: key =  -7; return key; break; //SHIFT
				case SDLK_SPACE : key =  -8; return key; break; //SPACE
				case SDLK_RETURN: key =  -9; return key; break; //ENTER
				//default			: return  0; break; //NO KEY
				}
			}

			if( event.type == SDL_KEYDOWN )
			{
				switch( event.key.keysym.sym )
				{
				case SDLK_UP    : key =  1; return key; break;  //UP Arrow
				case SDLK_DOWN  : key =  2; return key; break;  //DOWN Arrow
				case SDLK_RIGHT : key =  3; return key; break;  //RIGHT Arrow
				case SDLK_LEFT  : key =  4; return key; break;  //LEFT Arrow
				case SDLK_RCTRL : key =  5; return key; break;  //CTRL
				case SDLK_LCTRL : key =  5; return key; break;  //CTRL
				case SDLK_RALT  : key =  6; return key; break;  //ALT
				case SDLK_LALT  : key =  6; return key; break;  //ALT
				case SDLK_RSHIFT: key =  7; return key; break;  //SHIFT
				case SDLK_LSHIFT: key =  7; return key; break;  //SHIFT
				case SDLK_SPACE : key =  8; return key; break;  //SPACE
				case SDLK_RETURN: key =  9; return key; break;  //ENTER
				//default			: return 0; break;  //NO KEY
				}
			}
			
		}
		return key;
	}
} game;

I declared automatically game object because I need to access the screen var from other classes. Is it possible to make it someway same for all objects of cGame class. (Screen must be same for all objects, so not more than one screen surface can exist).

Thanks in advance!
You need to define static members:
SDL_Surface * cGame::screen=0;
How can I use that I don't understand?
Can you give me a sample.
Thanks!
Topic archived. No new replies allowed.