'{'标记之前的预期类名,类继承
expected class-name before '{' token, class inheritance
本文关键字:继承 更新时间:2023-10-16
我的项目的一个文件有问题,我想是由一些包含问题引起的。代码本身运行良好,但由于我更改了其他一些文件中的一些行,我在"{"token"错误之前得到了一个"预期类名"。我已经尝试过使用前向声明,但错误更改为"无效使用不完整类型"class Entity"(文章末尾的生成报告行)。
EntityPlayer.h
#ifndef _SHARED_GAME_ENTITY_ENTITYPLAYER_H_
#define _SHARED_GAME_ENTITY_ENTITYPLAYER_H_
//////////////////////////////////////////////////
//////////////////// INCLUDES ////////////////////
//////////////////////////////////////////////////
#include<array>
#include<iostream>
#include<windows.h>
#include<SFML/System.hpp>
#include<Shared/Game/Entity/Entity.h>
#include<Shared/Game/ItemStack.h>
#include<Shared/Game/Items.h>
#include<Shared/System/Types.h>
//////////////////////////////////////////////////
////////// STRUKTUREN; KLASSEN; OBJEKTE //////////
//////////////////////////////////////////////////
//class Entity; //forward declaration of 'class Entity' -> invalid use of incomplete type 'class Entity' line 27
class ItemStack;
class Items;
class EntityPlayer : public Entity{ //line 27
public:
struct PlayerStats{
int health;
};
EntityPlayer(const std::string ID, const GameMode mode);
virtual ~EntityPlayer();
virtual void update();
virtual void setGameMode(const GameMode mode);
virtual bool isInventoryOpen();
virtual bool isInInventory(ItemStack* item);
virtual bool removeFromInventory(ItemStack *item);
virtual uint addToInventory(ItemStack* item);
virtual PlayerStats getPlayerStats();
virtual AABB getAABB();
virtual std::array<ItemStack*, 10> getHotbarItems();
virtual std::array<ItemStack*, 40> getInventory();
protected:
virtual bool isInventorySlotFree();
virtual bool isHotbarSlotFree();
virtual bool addToHotbarSlot(ItemStack* itemstack);
bool m_inventoryOpen;
bool m_ltp;
GameMode m_mode;
PlayerStats m_stats;
std::array<ItemStack*, 10> m_itemsHotbar;
std::array<ItemStack*, 40> m_inventory;
};
//////////////////////////////////////////////////
/////////////////// PROTOTYPEN ///////////////////
//////////////////////////////////////////////////
#endif // _SHARED_GAME_ENTITY_ENTITYPLAYER_H_
实体.h
#ifndef _SHARED_GAME_ENTITY_ENTITY_H_
#define _SHARED_GAME_ENTITY_ENTITY_H_
//////////////////////////////////////////////////
//////////////////// INCLUDES ////////////////////
//////////////////////////////////////////////////
#include<map>
#include<iostream>
#include<windows.h>
#include<Shared/Game/World.h>
#include<Shared/System/Defines.h>
#include<Shared/System/Log.h>
#include<Shared/System/Types.h>
//////////////////////////////////////////////////
////////// STRUKTUREN; KLASSEN; OBJEKTE //////////
//////////////////////////////////////////////////
class World;
class Entity{
friend class GameRegistry;
#ifdef CLIENT
friend class GameRenderer;
#endif // CLIENT
public:
Entity(const std::string ID, const std::string texture);
virtual ~Entity();
virtual void update();
virtual bool linkWorld(World* world);
virtual bool isWorldLinked();
virtual bool setPosition(const Vec3d position);
virtual bool move(const Vec2zd value);
virtual bool move(const double x, const double z);
virtual float getRotation();
virtual Vec3d getPosition();
virtual std::string getID();
virtual std::string getTextureName();
virtual std::string getTextureLocation();
virtual AABB getAABB();
protected:
virtual int getNumericID();
int m_numericID;
float m_rotation;
World* m_world;
Vec3d m_position;
std::string m_id;
std::string m_texture;
public:
static bool isEntityRegistered(const std::string name);
static Entity getEntityCopy(const std::string name);
protected:
static std::map<std::string, Entity*> m_entitys;
};
//////////////////////////////////////////////////
/////////////////// PROTOTYPEN ///////////////////
//////////////////////////////////////////////////
#endif // _SHARED_GAME_ENTITY_ENTITY_H_
错误"在"{"标记"之前应为类名:
In file included from src/Shared/Game/CraftingManager.h:13:0,
from src/Shared/Game/GameRegistry.h:16,
from src/Shared/Game/Blocks.h:18,
from src/Shared/Game/World.h:12,
from src/Shared/Game/Entity/Entity.h:12,
from E:MasterSProjekteC++SpieleProject 008srcSharedGameEntityEntity.cpp:1:
src/Shared/Game/Entity/EntityPlayer.h:28:35: error: expected class-name before '{' token
class EntityPlayer : public Entity{
^
错误"无效使用不完整的类型":
In file included from src/Shared/Game/CraftingManager.h:13:0,
from src/Shared/Game/GameRegistry.h:16,
from src/Shared/Game/Blocks.h:18,
from src/Shared/Game/World.h:12,
from src/Shared/Game/Entity/Entity.h:12,
from E:MasterSProjekteC++SpieleProject 008srcSharedGameEntityEntity.cpp:1:
src/Shared/Game/Entity/EntityPlayer.h:28:29: error: invalid use of incomplete type 'class Entity'
class EntityPlayer : public Entity{
^
src/Shared/Game/Entity/EntityPlayer.h:24:7: error: forward declaration of 'class Entity'
class Entity; //forward declaration of 'class Entity' -> invalid use of incomplete type 'class Entity' line 27
^
我不知道你需要帮助我包含的文件中的哪一个,但错误列表中列出的文件中没有一个包含文件Entity.h的包含。
提前非常感谢您,希望您能帮助我:)
只是将其标记为已回答。解释讨论:检查您的包含链,看看您是否包含Entity.h中的EntityPlayer.h。
相关文章:
- 继承函数的重载解析
- 继承期间显示未知行为的子类
- 头文件-继承c++
- 为什么在保护模式下继承升级不起作用
- 通过继承类使用来自不同命名空间的运算符
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 混合组合和继承的C++问题
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 从类继承时,继承的类是否会通过父类重新定义继承的变量
- 公共与私人继承
- 如何创建从同一类继承的不同对象的向量
- 如何从另一个文件继承私有成员变量和公共函数
- 在模板基类中为继承类中的可选重写生成虚拟方法
- 带有继承的C++工厂
- 我应该避免多重实现继承吗
- C++继承更改成员
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 关于C++中具有多重继承"this"指针的说明
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 如何在QT Creator上将QWidget声明为继承类的对象