У меня проблема с файлом моего проекта, я думаю, вызванный некоторыми проблемами. Сам код работал нормально, но поскольку я изменил некоторые строки в некоторых других файлах, я получаю «ожидаемое имя класса до» {«токен». Я уже пытался использовать форвардные объявления, но с ними ошибка изменяется на «недопустимое использование класса неполного типа 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_
Entity.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:\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
^
Я не знаю, какой из включенных файлов вам понадобится, но ни один из файлов, перечисленных в списке ошибок, не включает в себя файл Entity.h.
Большое спасибо заранее, надеюсь, что вы можете мне помочь :)
Вы не можете получить класс, используя объявление вперед. Определение базового класса должно быть доступно для его вывода. Попробуйте '# include' в заголовочном файле, где определен' class Entity'. –
каждый включенный файл должен иметь соответствующий '.cpp', который включает его, даже если он в противном случае пуст, это поможет найти проблемы в базе include и не дожидаться его включения в другое место. Если вы это сделаете, вы можете найти проблему в другом файле include, вызывающем эту проблему. –
В изменениях, которые вы недавно делали, не включили ли вы 'EntityPlayer.h' из' Entity.h'? Если 'Сам код работал нормально, но поскольку я изменил некоторые строки ...', то почему бы вам не отменить свои изменения, чтобы вернуться к чему-то работающему, а затем повторить изменения один за другим, чтобы определить тот, который ведет к вашей ошибке ? Тогда вы можете опубликовать лучший вопрос с хорошими исходными данными. – jpo38