幸运的是,这可能是一些非常明显的事情从我身边溜走了,但我已经在 C2143 上挣扎了很长一段时间,而且我被难住了。
game.h(21): error C2143: syntax error : missing ';' before '*'
game.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
游戏.h
#ifndef GAME_H_
#define GAME_H_
#include <irrlicht.h>
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::io;
using namespace irr::gui;
#include <iostream>
#include "CInput.h"
#include "CAssets.h"
using namespace rtsirr;
IrrlichtDevice *device = 0;
IVideoDriver *driver = 0;
ISceneManager *manager = 0;
CAssets *assets = 0; // Line 21, error here
#endif
CAssets.h
#ifndef ASSETS_H_
#define ASSETS_H_
#include "Game.h"
namespace rtsirr {
class CAssets
{
public:
CAssets();
virtual ~CAssets();
ITexture* getTexture(stringw name);
IMesh* getMesh(stringw name);
IAnimatedMesh* getAnimatedMesh(stringw name);
void load();
private:
map<stringw, ITexture *> *textures;
map<stringw, IMesh *> *meshes;
map<stringw, IAnimatedMesh *> *animatedMeshes;
};
}
#endif
似乎 CAssets 没有被识别为有效类型,但我不明白为什么。是什么导致了这个问题?
谢谢。
最佳答案
您的包含中有循环依赖。 Game.h
包含 CAssets.h
,后者在定义 CAssets
之前又包含 Game.h
。预处理器的结果会有所不同,具体取决于包含的顺序。
从您的示例代码来看,似乎 Game.h
实际上不需要了解太多关于 CAssets
的信息,除了它是一种类型。您可以用前向声明替换 CAssets.h
的包含:
class CAssets;
您甚至可以提供仅执行此操作的 CAssets_fwd.h
。否则,您将需要打破这两个 header 之间的循环依赖。
关于c++ - vs2012编译器错误C2143 : missing ; before *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14015620/