2016-03-17 379 views
0

所以我使用sfml制作了一个非常简单的游戏,但遇到了这个问题。在使用相同的课程和设计之前,我做了一个游戏。但是我遇到了Player* player;和另一个课Level level的问题。缺少类型说明符 - int假定(类问题)

这次我做错了什么。我不记得我上次为这个特定部分做了什么(因为我没有遇到这个问题),我没有这些文件了。

继承人头文件。

#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; 
}; 
+0

以任何机会,你包括player.h level.h?如果是这样的话,那就是循环依赖问题。 – Atul

回答

0

这似乎是一个循环依赖问题。见Resolve header include circular dependencies

您需要转发声明球员,并采取了包括Player.h像这样:

#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; 
}; 
+0

原来我能够通过从application.h中删除一些东西来解决循环依赖问题,这是在player.h中需要的,因为我在application.h中有其他依赖项。然后,我将它移到了不同​​的头文件中,并从player.h中删除了它,并解决了这两个依赖关系。 –

相关问题