i have been following this tutorial. However when i try and run it i get these errors:
I cannot see why i am getting them..

1>------ Build started: Project: Ninja Wars, Configuration: Debug Win32 ------
1>  Playstate.cpp
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\playstate.cpp(8): error C2259: 'PlayState' : cannot instantiate abstract class
1>          due to following members:
1>          'void GameState::Cleanup(void)' : is abstract
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(10) : see declaration of 'GameState::Cleanup'
1>  PauseState.cpp
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\pausestate.cpp(7): error C2259: 'PauseState' : cannot instantiate abstract class
1>          due to following members:
1>          'void GameState::Cleanup(void)' : is abstract
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(10) : see declaration of 'GameState::Cleanup'
1>  MenuState.cpp
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\menustate.cpp(8): error C2259: 'MenuState' : cannot instantiate abstract class
1>          due to following members:
1>          'void GameState::Cleanup(void)' : is abstract
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(10) : see declaration of 'GameState::Cleanup'
1>  Game.cpp
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\game.cpp(46): error C2039: 'Clean' : is not a member of 'GameState'
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(7) : see declaration of 'GameState'
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\game.cpp(77): error C2039: 'Clean' : is not a member of 'GameState'
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(7) : see declaration of 'GameState'
1>c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\game.cpp(113): error C2039: 'Clean' : is not a member of 'GameState'
1>          c:\documents and settings\louisa\my documents\visual studio 2010\projects\ninja wars\ninja wars\gamestate.h(7) : see declaration of 'GameState'
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Compiler Error C2259

>> I cannot see why i am getting them..
For future reference, it's better to post the offending code along with the error messages.

post ur cpp files
only then error can be found

From the compiler errors you've tried to instantiate an abstract class.

Abstract classes cannot be instantiated and must be inherited.

This is an abstract class:

class MyAbstract
{
public:
     virtual void PrintLetter(char letter) = 0;
}

To use an abstract class you must inherit it and override the virtual function

class MyClass : MyAbstract
{
public:
     void PrintLetter(char letter) { std::cout << letter; }
}

To apply this specifically to your code. Your GameState class has an abstract function called "Cleanup". You must inherit GameState into your own class and override the "Cleanup" method.

Secondly, you've tried to use the method "Clean". This doesn't exist in the GameState class at all.

Have you copied the code from the tutorial and tried to compile it before completing the tutorial?

no i finished the whole tutorial.

#define GAMESTATE_H

#include "Game.h"

class GameState
        {
        public:
                virtual void Init() = 0;
                virtual void Cleanup() = 0;
                
                virtual void Pause() = 0;
                virtual void Resume() = 0;
                
                virtual void HandleEvents(Game* game) = 0;
                virtual void Update(Game* game) = 0;
                virtual void Draw(Game* game) = 0;
			
                void ChangeState(Game* game, GameState* state) {
                        game->ChangeState(state);
                }
                
        protected:
                GameState() { }
};
#endif
#include "Game.h"
#include "GameState.h"



// constructor
Game::Game()
{
  
}

void Game::Init(const char* title, int width, int height, 
                                int bpp, bool fullscreen)
{
        int flags = 0;
        
        // initialize SDL
        SDL_Init(SDL_INIT_EVERYTHING);
        
        // set the title bar text
        SDL_WM_SetCaption(title, title);
        
        if ( fullscreen ) {
                flags = SDL_FULLSCREEN;
        }
        
        // create the screen surface
        m_pScreen = SDL_SetVideoMode(width, height, bpp, flags);
        
        m_bFullscreen = fullscreen;
        
        m_bRunning = true;

                // print our success
        printf("Game Initialised Succesfully\n");
		}


void Game::ChangeState(GameState* state) 
{
        // cleanup the current state
        if ( !states.empty() ) {
                states.back()->Clean();
                states.pop_back();
        }
        
        // store and init the new state
        states.push_back(state);
        states.back()->Init();
}

/*
Whereas ChangeState() pushes a state onto the stack and removes the previous state, PushState() pauses the previous state before pushing a new state onto the stack, this state can then be removed and the previous state resumed. Extrememly useful for pausing.
*/
void Game::PushState(GameState* state)
{
        // pause current state
        if ( !states.empty() ) {
                states.back()->Pause();
        }
        
        // store and init the new state
        states.push_back(state);
        states.back()->Init();
}

/*
Remove and resume previous state.
*/
void Game::PopState()
{
        // cleanup the current state
        if ( !states.empty() ) {
                states.back()->Clean();
                states.pop_back();
        }
        
        // resume previous state
        if ( !states.empty() ) {
                states.back()->Resume();
        }
}

/*
These functions have now been changed so that they simply allow the current state to handle things, states.back() refers to the last element on the stack (the current state)
*/
void Game::HandleEvents()
{
        // let the state handle events
        states.back()->HandleEvents(this);
}


void Game::Update()
{
        // let the state update the game
        states.back()->Update(this);
}

void Game::Draw()
{
        // let the state draw the screen
        states.back()->Draw(this);
        //SDL_Flip(m_pScreen);
}

void Game::Clean()
{
        while ( !states.empty() ) {
                states.back()->Clean();
                states.pop_back();
        }
        
        // shutdown SDL
        SDL_Quit();
}
#include <stdio.h>

#include "SDL.h"
#include "Game.h"
#include "MenuState.h"
#include "PlayState.h"

MenuState MenuState::m_MenuState;

void MenuState::Init()
{       
        menuSprite = NULL; // set pointer to NULL;
        menuSprite = Sprite::Load("menustate.bmp"); // load menu state bitmap
        printf("MenuState Init Successful\n");
}

void MenuState::Clean()
{
        printf("MenuState Clean Successful\n");
}

void MenuState::Pause()
{
        printf("MenuState Paused\n");
}

void MenuState::Resume()
{
        printf("MenuState Resumed\n");
}

void MenuState::HandleEvents(Game* game) //put our exit function back in business
                                                                                 // we can now quit with cross in corner.
{
        SDL_Event event;
        
        if (SDL_PollEvent(&event)) {
                switch (event.type) {
                        case SDL_QUIT:
                                game->Quit();
                                break;
								
							case SDL_KEYDOWN:
                                 switch(event.key.keysym.sym){

                                 case SDLK_SPACE:
                                          game->ChangeState(PlayState::Instance());
                                          break;
                         }
                }
        }
}

void MenuState::Update(Game* game) 
{
}

void MenuState::Draw(Game* game) 
{
   Sprite::Draw(game->GetScreen(), menuSprite, 0, 0); // we will write 
                                                                                                          // GetScreen() in a second
   SDL_Flip(game->GetScreen());
}
#include <stdio.h>

#include "SDL.h"
#include "Game.h"
#include "PlayState.h"
#include "PauseState.h"

PlayState PlayState::m_PlayState;

void PlayState::Init()
{       
        playSprite = NULL;
        
        playSprite = Sprite::Load("playstate.bmp");
        
        printf("PlayState Init Successful\n");
}

void PlayState::Clean()
{
        printf("PlayState Clean Successful\n");
}

void PlayState::Pause()
{
        printf("PlayState Paused\n");
}

void PlayState::Resume()
{
        printf("PlayState Resumed\n");
}

void PlayState::HandleEvents(Game* game)
{
        SDL_Event event;
        
        if (SDL_PollEvent(&event)) {
                switch (event.type) {
                        case SDL_QUIT:
                                game->Quit();
                                break;

						case SDL_KEYDOWN:
                                switch(event.key.keysym.sym){
                        case SDLK_SPACE:
                                game->PushState(PauseState::Instance());
                                break;
                         }
                }
        }
}


void PlayState::Update(Game* game) 
{
}

void PlayState::Draw(Game* game) 
{
        Sprite::Draw(game->GetScreen(), playSprite, 0, 0);
        SDL_Flip(game->GetScreen());
}

These are all the classes i think i am getting the errors from. can anyone see what i have to do?

Please include the header files for your classes =)

these are the header files for the game.ccp, playstate.cpp and menustate.cpp

#ifndef  _GAME_H_
#define _GAME_H_

#include <SDL.h>

#include "Sprite.h"

#include <vector>

class GameState; // make sure this class knows about the GameState class.

class Game
        {
        public:
                
                Game();
                
                void Init(const char* title, int width, int height, 
                                  int bpp, bool fullscreen);
                
                void ChangeState(GameState* state); // new function
                void PushState(GameState* state);  // new function
                void PopState(); // new function
                
                void HandleEvents(); // remove pointer to game class
                
                void Update();
                
                void Draw();
                
                void Clean();
                
                bool Running() { return m_bRunning; }
                void Quit() { m_bRunning = false; }

				SDL_Surface* GetScreen() {return m_pScreen;}
                
        private:
                
                // the stack of states
                std::vector<GameState*> states;
                
                SDL_Surface* m_pScreen;
                
                bool m_bFullscreen;
                bool m_bRunning;
                
};
#endif
#ifndef  _PLAY_STATE_H_
#define _PLAY_STATE_H_

#include "SDL.h"
#include "GameState.h"
#include "Sprite.h"

class PlayState : public GameState
{
        public:
                void Init();
                void Clean();
                
                void Pause();
                void Resume();
                
                void HandleEvents(Game* game);
                void Update(Game* game);
                void Draw(Game* game);
                
                // Implement Singleton Pattern
                static PlayState* Instance()
                {
                        return &m_PlayState;
                }
                
        protected:
                
                PlayState() {}
                
        private:
                static PlayState m_PlayState;
                
                SDL_Surface* playSprite;
                
};

#endif
#ifndef _MENU_STATE_H_
#define _MENU_STATE_H_

#include "SDL.h"
#include "GameState.h"
#include "Sprite.h"

class MenuState : public GameState
{
        public:
                void Init();
                void Clean();
                
                void Pause();
                void Resume();
                
                void HandleEvents(Game* game);
                void Update(Game* game);
                void Draw(Game* game);
                
                // Implement Singleton Pattern
                static MenuState* Instance()
                {
                        return &m_MenuState;
                }
                
        protected:
                
                MenuState() {}
                
        private:
                static MenuState m_MenuState;
                
                SDL_Surface* menuSprite;
                
};

#endif

There is no implementation for the pure virtual function

virtual void Cleanup() = 0;

in the child classes of GameState. Probably the function 'Clean' in PlayState and MenuState has to be named Cleanup?

There is no implementation for the pure virtual function

virtual void Cleanup() = 0;

in the child classes of GameState. Probably the function 'Clean' in PlayState and MenuState has to be named Cleanup?

I think i fixed this part of the problem by changing the cleans to cleanup but now i get a different error message which i don't understand at all..

1>------ Build started: Project: Ninja Wars, Configuration: Debug Win32 ------
1>  PauseState.cpp
1>Game.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class GameState * const & __thiscall std::_Vector_const_iterator<class std::_Vector_val<class GameState *,class std::allocator<class GameState *> > >::operator*(void)const " (??D?$_Vector_const_iterator@V?$_Vector_val@PAVGameState@@V?$allocator@PAVGameState@@@std@@@std@@@std@@QBEABQAVGameState@@XZ)
1>MenuState.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl Sprite::Draw(struct SDL_Surface *,struct SDL_Surface *,int,int)" (?Draw@Sprite@@SA_NPAUSDL_Surface@@0HH@Z) referenced in function "public: virtual void __thiscall MenuState::Draw(class Game *)" (?Draw@MenuState@@UAEXPAVGame@@@Z)
1>PauseState.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl Sprite::Draw(struct SDL_Surface *,struct SDL_Surface *,int,int)" (?Draw@Sprite@@SA_NPAUSDL_Surface@@0HH@Z)
1>Playstate.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl Sprite::Draw(struct SDL_Surface *,struct SDL_Surface *,int,int)" (?Draw@Sprite@@SA_NPAUSDL_Surface@@0HH@Z)
1>C:\Documents and Settings\Louisa\my documents\visual studio 2010\Projects\Ninja Wars\Debug\Ninja Wars.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This says to me that you haven't included the SDL Libraries in your linker.

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.