C++ 在'之前应为类名;{';标记,类继承
我的项目的一个文件有问题,我猜是由一些include问题引起的。代码本身工作正常,但由于我更改了一些其他文件中的一些行,我在“{”token“错误之前得到了一个“预期的类名”。我已经尝试使用前向声明,但错误更改为“无效使用不完整类型”类实体“(文章末尾的构建报告行) 整层C++ 在'之前应为类名;{';标记,类继承,c++,windows,forward-declaration,incomplete-type,expected-exception,C++,Windows,Forward Declaration,Incomplete Type,Expected Exception,我的项目的一个文件有问题,我猜是由一些include问题引起的。代码本身工作正常,但由于我更改了一些其他文件中的一些行,我在“{”token“错误之前得到了一个“预期的类名”。我已经尝试使用前向声明,但错误更改为“无效使用不完整类型”类实体“(文章末尾的构建报告行) 整层 #ifndef _SHARED_GAME_ENTITY_ENTITYPLAYER_H_ #define _SHARED_GAME_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_
错误“不完整类型的无效使用”:
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:\MasterS\Projekte\C++\Spiele\Project 008\src\Shared\Game\Entity\Entity.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
^
我不知道您需要哪些包含的文件来帮助我,但错误列表中列出的文件中没有一个包含文件实体.h
提前非常感谢,希望您能帮助我:)仅将此标记为已回答。解释讨论内容:检查包含链,查看是否包含Entity.h中的EntityLayer.h。不能使用转发声明从类派生。基类的定义必须可用,才能从中派生。请尝试使用
包含头文件,其中类定义了tity
。每个包含文件都应该有一个相应的包含它的.cpp
,即使它是空的,这将有助于在基本包含中查找问题,而不是等待它被包含在其他位置。如果这样做,您可能会在另一个包含文件中发现导致此问题的问题。在您最近所做的更改中,didn您不包括Entity.h
中的EntityPlayer.h
吗?如果代码本身工作正常,但由于我更改了一些行…
,那么,为什么不撤消更改以移回工作状态,然后逐个重复更改以确定导致错误的更改?然后您可以使用go发布一个更好的问题od输入。类实体包含在“#include”中,所有包含的文件都有一个.cpp文件,实体类到目前为止工作正常,在错误发生之前,我没有更改其中的任何内容,所有内容都变好了,我没有更改实体或EntityLayer文件本身中的任何内容,但在包括这些内容的其他文件中,我无法更改我没有更改,因为我昨天试图自己解决问题,在更改之前我没有代码备份
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:\MasterS\Projekte\C++\Spiele\Project 008\src\Shared\Game\Entity\Entity.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:\MasterS\Projekte\C++\Spiele\Project 008\src\Shared\Game\Entity\Entity.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
^