【问题标题】:C2065: 'class' undeclared identifier, header includedC2065:“类”未声明的标识符,包含标头
【发布时间】:2015-04-12 21:42:39
【问题描述】:

我想通过测试生成器来运行游戏。我认为我已经通过在 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?

【问题讨论】:

  • 为什么不想转发声明?
  • @dwcanillas 我试过了,但是我得到了没有定义的错误,特别是在实现的时候,我不想要它,因为我没有建立循环依赖
  • 确切的错误信息是什么?你#include &lt;vector&gt;了吗?
  • 听起来你应该在标题中转发声明 Spawner 并在源中 #include
  • @dwcanillas 谢谢!现在我必须解决链接器问题

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


【解决方案1】:
C2065: 'class' undeclared identifier

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 2011-02-15
    • 2011-04-16
    • 2011-04-16
    • 2010-12-24
    • 2023-03-04
    相关资源
    最近更新 更多