gpt4 book ai didi

c++ - vs2012编译错误C2143 : missing ; before *

转载 作者:搜寻专家 更新时间:2023-10-31 01:51:15 24 4
gpt4 key购买 nike

幸运的是,我可能忽略了一些非常明显的事情,但我已经在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com