C2065:' class'未声明的标识符,包括标题

时间:2015-04-12 21:42:39

标签: c++ header-files undeclared-identifier

我想通过测试spawner来运行游戏。我以为我通过在SceneGame.hpp中调用它的头文件来正确地声明了Spawner类

当我想使用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?

1 个答案:

答案 0 :(得分:1)

C2065: 'class' undeclared identifier

如果这是错误消息的文字文本,那么您将编译为C,而不是C ++。

如果它不是错误消息的文字文本,那么您应该已经发布了错误消息的文字文本。