包括头文件导致类型丢失

时间:2019-03-06 20:39:00

标签: c++ compiler-errors include

我正在重新研究C ++,并尝试编写一个小型游戏。该程序运行良好,直到我将Game.h包含在InputManager.h中。

#ifndef GAME
#define GAME

#include <memory>
#include <string>
#include <SFML/Graphics.hpp>
#include "StateMachine.h"
#include "AssetManager.h"
#include "InputManager.h"

namespace tryEngine
{   
    struct GameData 
    {
        StateMachine machine;
        sf::RenderWindow window;
        sf::View view;
        AssetManager assets;
        InputManager input;
    };

    typedef std::shared_ptr<GameData> GameDataRef;

    class Game
    {
    public:
        Game(int width, int height, std::string title);

    private:
        const float dt = 1.0f / 80.0f; // time per frame if targeting 80fps
        sf::Clock _clock; // handles frame pauses

        GameDataRef _data = std::make_shared<GameData>();

        void Run();
    };
}

#endif // GAME

和另一个

#ifndef INPUTMANAGER
#define INPUTMANAGER

#include "Game.h"

namespace tryEngine
{
    class InputManager
    {
    public:
        InputManager() { _pressedShift = false; };
        ~InputManager() {};

        bool IsSpriteClicked(sf::Sprite object, sf::Mouse::Button button, sf::RenderWindow &window);
        bool IsSpriteClicked(sf::Sprite object, sf::Mouse::Button button, sf::RenderWindow & window, bool centered);
        bool IsKeyPressed(sf::Keyboard::Key key);

        //sf::Vector2f getMousePosition(GameDataRef data);
        //sf::Vector2f getMouseBlockPosition(GameDataRef data);

        bool WasKeyPressed(sf::Keyboard::Key key);

    private:
        bool _pressedShift;
    };
}

#endif // INPUTMANAGER

编译器抱怨Game.cpp第19行中都存在未知的覆盖说明符'input'和缺少类型说明符。似乎他不再包含InputManager,因为他无法将其识别为类型,但是为什么呢?我想在InputManager中使用GameDataRef,我知道我需要对其进行前向声明,但是此错误确实阻止了我取得任何进展。

0 个答案:

没有答案