2015-04-12 66 views
-1

我想通過測試spawner來運行遊戲。我認爲我已經通過在SceneGame.hpp中調用它的頭文件正確聲明瞭Spawner類C2065:'class'未聲明的標識符,頭部包含

當我想將Spawner *用作矢量變量時,我認爲不會有編譯器錯誤,但我錯了。

錯誤的來源是在聲明變量矢量spawner_list

相關文件:

Spawner.hpp

#pragma once 

#include <SFML\Graphics.hpp> 

#include "weapon.hpp" 
#include "movement.hpp" 


// forward declare 

class EnemyTemplate; 

/* 
    Spawner will create enemies and/or power ups 

    For spawning enemies, they will recieve one weapon and one movement type 

    for powerups, only one will spawn and the spawner would disappear afterwards 

    The spawner will create entities through the following: 

    Spawn gap: the amount of time to wait between making enemies, in frame ticks 
    Spawn limit: the amount of enemies to make before being removed 



    */ 

class Spawner{ 
private: 

    int spawnGapTime; 
    int spawnGapSet; 

    // If you plan to spawn finite enemies, then use constructor 
    int spawnLimit = -1; 

    EnemyTemplate* enemyData; 
    Weapon* givenWeapon; 
    Movement* givenMovement; 



    int ticks; 

public: 

    Spawner(Weapon*, Movement*, EnemyTemplate*, std::vector <int>); 

    void update(); 
    void spawn_enemy(); 
    void spawn_count(); 

    ~Spawner(){ 
     delete givenWeapon; 
     delete givenMovement; 
     delete enemyData; 
    }; 


}; 

SceneGame.hpp

#pragma once 

#include <SFML\Graphics.hpp> 

#include "scene.hpp" 
#include "game.hpp" 
#include "entity.hpp" 
#include "movement.hpp" 
#include "weapon.hpp" 
#include "player.hpp" 
#include "collisionGrid.hpp" 

#include "spawner.hpp" 

// forward declare 

class BulletTemplate; 

class SceneGame : public Scene{ 
private: 

// skipping some code 

std::vector <Spawner*> spawner_list; // The source of the error 


public: 
SceneGame(Game* game); 

// skipping some code 

}; 

有什麼我可以修復這個未聲明的標識符問題,而不必爲此而煩惱病房宣佈Spawner?

+0

你爲什麼不想轉發聲明? – dwcanillas

+0

@dwcanillas我已經嘗試過了,但是我得到了沒有定義的錯誤,特別是在執行時,我不想要它,因爲我沒有做出循環依賴 – JBRPG

+0

什麼是確切的錯誤消息?你有沒有'#包括'? –

回答

1
C2065: 'class' undeclared identifier 

如果這是錯誤消息的文本文本,則編譯爲C,而不是C++。

如果它不是錯誤消息的文本文本,則應該發佈錯誤消息的文本文本。

相關問題