2

幸运的是,这可能是很明显的事情从我身边溜走了,但是我已经在 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 没有被识别为有效类型,但我不知道为什么。是什么导致了这个问题?

谢谢。

4

1 回答 1

3

您的include中有一个循环依赖项。包括在定义之前又包括在内。预处理器的结果会有所不同,具体取决于包含的顺序。Game.hCAssets.hGame.hCAssets

从您的示例代码看来,除了类型之外,似乎Game.h不需要了解太多。CAssets您可以将包含替换为CAssets.h前向声明:

class CAssets;

你甚至可以提供一个CAssets_fwd.h只做那个的。否则,您将需要打破这两个标头之间的循环依赖关系。

于 2012-12-23T23:48:04.660 回答