I am using Visual C++ 2010 express edition and i am making classes but when i run i get the error:
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\game.cpp(71): error C2065: 'm_pScreen' : undeclared identifier

In my Game.cpp i have this code
void Game::Draw()
{
	Sprite::Draw(m_pScreen, testSprite, 0, 0);
	Sprite::Draw(m_pScreen, testSprite, 300, 300, 0, 0, 50, 50);

}

And i have been told to add:
When testing the function in Game::Draw() add SDL_Flip(m_pScreen);

In my game.h i have
Game();
                         
						void Init(const char* title, int width, int height, 
                                  int bpp, bool fullscreen);

                          
						  bool Running() {return m_bRunning;}

                          void HandleEvents(Game* game);
                           
                          void Update();
                           
			 void Draw();

                          void Clean();

can anyone see where i can add it where it fixes the error.

Dani AI

Generated

The compiler error means the identifier m_pScreen is not visible where Draw() is compiled. As pointed out, that almost always means the member was never declared (or the .cpp cannot see the declaration). The advice to "flip/present" the screen after drawing is fine, but it comes after you declare and initialize the screen pointer.

Add a screen pointer as a member of the Game class (in the header) and initialize it when you set up SDL. Example declaration:

/* in Game.h, inside the Game class */
private:
    SDL_Surface* m_pScreen;   // screen surface for SDL 1.2

Initialize the member during your startup/Init routine (example for SDL 1.2):

/* in Game.cpp Init(...) */
m_pScreen = SDL_SetVideoMode(width, height, bpp, fullscreen ? SDL_FULLSCREEN : 0);
if (!m_pScreen) {
    fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
    m_bRunning = false;
}

Practical checks and common pitfalls: make sure #include <SDL.h> (or the correct SDL2 headers) is present where the type is used; ensure Game.cpp includes Game.h; confirm the name is spelled exactly m_pScreen (no typos or different casing); place the declaration in the class scope (not inside a function); and clean/rebuild the project after changes. If you are using SDL2, use the SDL2 window/surface or renderer APIs and call the appropriate present/update function for that API rather than the SDL 1.2 calls.

The error message is clear: 'm_pScreen' : undeclared identifier tells you that you have tried to use an identifier m_pScreen and that identifier is not declared in the scope that is in effect at line 71. Judging from the horrible Hungarian notation name, it should be a member of the Game class which is a pointer to a Screen. Presumably you didn't declare this member in the Game class declaration (and so, probably, you also didn't initialize it in the constructor).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.