Forward declaration error

I get a compiler error in gamestate.h and I'm not sure what's causing it because introstate.h is setup in a similar manner but working fine. The error message is:

|In member function 'void GameState::ChangeState(GameEngine*, GameState*)':|
|error: invalid use of incomplete type 'class GameEngine'|
|error: forward declaration of 'class GameEngine'|



gamestate.h
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
// include guard
#pragma once

class GameEngine;

#include "gameengine.h"
#include <SFML/Window.hpp>


class GameState
{
    public:
        virtual void Init() = 0;
        virtual void Cleanup() = 0;

        virtual void Pause() = 0;
        virtual void Resume() = 0;

        virtual void HandleEvents(GameEngine* game, sf::Window* window) = 0;
        virtual void Update(GameEngine* game) = 0;
        virtual void Draw(GameEngine* game) = 0;

// error in the following line
        void ChangeState(GameEngine* game, GameState* state) { game->ChangeState(state); }

    protected:
        GameState() {}
};



introstate.h
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
// include guard
#pragma once

class GameEngine;

#include "gamestate.h"
#include "gameengine.h"
#include <SFML/Window.hpp>

class IntroState : public GameState
{
    public:
        void Init();
        void Cleanup();

        void Pause();
        void Resume();

        void HandleEvents(GameEngine* game, sf::Window* window) ;
        void Update(GameEngine* game);
        void Draw(GameEngine* game);

        void ChangeState(GameEngine* game, GameState* state);

    protected:
        IntroState() {}
};
Last edited on
Can you elaborate?
In `gamestate.h' you are dereferencing the pointer, a forward declare is not good enough.
Post `gameengine.h'.


By the way, ¿why is `ChangeState()' a member function if you don't use the state of the caller? (or better, ¿why don't you use the state instead of passing a pointer?
void ChangeState(GameEngine* game) { game->ChangeState(this); } )
Topic archived. No new replies allowed.