-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?
你爲什麼不想轉發聲明? – dwcanillas
@dwcanillas我已經嘗試過了,但是我得到了沒有定義的錯誤,特別是在執行時,我不想要它,因爲我沒有做出循環依賴 – JBRPG
什麼是確切的錯誤消息?你有沒有'#包括'? –