0

So I'm making a very simple game using sfml but ran into this issue. I made a game before using the same classes and design etc. But I'm getting an issue with Player* player; and in another class Level level .

What am I doing wrong this time. I can't remember what I did last time for this particular part (since i didn't run into this issue) and I don't have the files anymore.

Heres the header file.

#pragma once
//level.h

//includes
#include "Player.h"
#include "GameObject.h"
#include <vector>
#include <ctime>
#include <SFML\Window\Keyboard.hpp>

//usings
using std::vector;
using sf::Keyboard;
class Level
{
public:
    Level();
    ~Level();
    void Update(), Render(sf::RenderWindow& window);
private:
    Player* player;
    void HandleInput(), Randomise(), Reset(), UserInterface(), Collisions(), GenerateObjects(), MoveObjects();

    vector<GameObject*> levelObjects;
    sf::FloatRect rectCollectible[5], rectPlayer;
    sf::Text timeText, scoreText;
    sf::Font font;
    sf::SoundBuffer collectibleBuffer;
    sf::Sound collectibleSound;
    sf::Texture spritesheet;
    bool mute, paused;
    int randomiser, spawnDelay, maxObjects;
};
  • By any chance are you including level.h in player.h? If that's the case then it's circular dependency issue. – Atul Mar 17 '16 at 03:19

1 Answers1

1

This seems to be a circular dependency issue. See Resolve header include circular dependencies

You need to forward declare Player and take out the include for Player.h like so:

#pragma once
//level.h

//includes
//#include "Player.h"
#include "GameObject.h"
#include <vector>
#include <ctime>
#include <SFML\Window\Keyboard.hpp>

//usings
using std::vector;
using sf::Keyboard;
class Player;
class Level
{
public:
    Level();
    ~Level();
    void Update(), Render(sf::RenderWindow& window);
private:
    Player* player;
    void HandleInput(), Randomise(), Reset(), UserInterface(), Collisions(), GenerateObjects(), MoveObjects();

    vector<GameObject*> levelObjects;
    sf::FloatRect rectCollectible[5], rectPlayer;
    sf::Text timeText, scoreText;
    sf::Font font;
    sf::SoundBuffer collectibleBuffer;
    sf::Sound collectibleSound;
    sf::Texture spritesheet;
    bool mute, paused;
    int randomiser, spawnDelay, maxObjects;
};
Community
  • 1
  • 1
wizurd
  • 3,541
  • 3
  • 33
  • 50
  • Turns out I was able to fix the circular dependency by removing some stuff from application.h which was needed in player.h as I had my other dependency in application.h. I then moved that to a different header file and removed that include from player.h and it solved both dependencies. – Aidan Mulvenna Mar 17 '16 at 09:14