我在Visual Studio 2017中遇到了一个奇怪的错误。错误是
错误C3646' collisionSys':未知的覆盖说明符
错误C4430缺少类型说明符 - 假设为int。注意:C ++没有 支持default-int
关于它的奇怪之处在于,当我构建解决方案时,我收到此错误但是当我删除collisionSys
的声明并构建,然后重新声明collisionSys
并再次构建时,它成功。虽然我在CollisionSystem.hpp
进行了一些更改后再次发生了
我的代码如下:
#ifndef COLLISION_SYSTEM__HPP
#define COLLISION_SYSTEM__HPP
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
#include "../EntityManager.hpp"
#include "../Entity.hpp"
#include "../Components/Display.hpp"
#include "../Components/Flags.hpp"
#include "../Components/Movement.hpp"
#include <Level.hpp>
class Level;
class CollisionSystem
{
public:
CollisionSystem();
void run(Level&, CameraSystem*, EntityManager*);
private:
static std::vector<std::shared_ptr<Entity>> m_Ents;
};
#endif
#include <Systems/CollisionSystem.hpp>
std::vector<std::shared_ptr<Entity>> CollisionSystem::m_Ents;
CollisionSystem::CollisionSystem()
{
}
void CollisionSystem::run(Level& level, CameraSystem* cameraSys,
EntityManager* EntMan)
{
// Some collision detection here
}
#ifndef LOCAL_WORLD__HPP
#define LOCAL_WORLD__HPP
#include <iostream>
#include <map>
#include <conio.h>
#include "GameState.hpp"
#include "StateMgr.hpp"
#include "Game.hpp"
#include "TileMap.hpp"
#include "Level.hpp"
#include "ECS/Entity.hpp"
#include "ECS/Components/IncludeAllComponents.hpp"
#include "ECS/ResourceManager.hpp"
#include "ECS/EntityManager.hpp"
#include "ECS/Systems/IncludeAllSystems.hpp"
// Map Names
enum class MapName
{
Map1
};
// Forward declaration
class Level;
class LocalWorld : public GameState
{
public:
LocalWorld();
~LocalWorld();
virtual void Pause();
virtual void Resume();
virtual void HandleEvents(sf::Event& eType);
virtual void Update();
virtual void Draw();
private:
std::map<MapName, Level*> Maps;
Level* activeLevel;
ResourceManager ResMan;
EntityManager EntMan;
CameraSystem cameraSys;
MovementSystem movementSys;
ControlSystem controlSys;
RenderSystem renderSys;
CollisionSystem collisionSys;
};
#endif
错误在CollisionSystem collisionSys;
LocalWorld.hpp
行
#ifndef INCLUDE_ALL_SYSTEMS__HPP
#define INCLUDE_ALL_SYSTEMS__HPP
#include "CameraSystem.hpp"
#include "ControlSystem.hpp"
#include "MovementSystem.hpp"
#include "RenderSystem.hpp"
#include "CollisionSystem.hpp"
#endif
此处此文件包含CollisionSystem.hpp
的所有系统
我查看了同样错误的其他问题,但仍无法修复。
将#include <Level.hpp>
从CollisionSystem.hpp
移至CollisionSystem.cpp
即可解决错误。任何人都能解释为什么会这样吗?