类错误导致几百个错误
Error with class causing a few hundred errors
我的类标题是
#ifndef _CENGINE_H
#define _CENGINE_H
#include "SFMLGraphics.hpp"
#include "CTextureManager.h"
#include "CTile.h"
class CEngine
{
private:
//Create instance of CTextureManager
CTextureManager textureManager;
//Load textures
void LoadTextures();
//New tile
CTile* testTile;
bool Running; //Is running?
sf::RenderWindow* window; //Create render window
public:
CEngine(); //Constructor
int Execute(); //Execute
bool OnInit(); //On intialization
void GameLoop(); //Main game loop
void Render(); //Render function
void Update(); //Update
};
#endif
现在它给我的 3 个错误是:
cengine.h(8):错误 C2236:意外的"类"CEngine"。你忘了";"吗?
cengine.h(8): 错误 C2143: 语法错误: 在"{"之前缺少";"
cengine.h(8): 错误 C2447: '{' : 缺少函数头(旧式正式列表?
我知道错误很明显,但我看不出类有问题。我可能真的很愚蠢,因为我累了。
这似乎是一个循环包含问题。CTextureManager.h
或CTile.h
是否包括彼此或CEngine.h
?
若要解决此问题,请尽可能使用前向声明。例如,您的类不需要包含CTile.h
- 它可能看起来像:
#ifndef CENGINE_H
#define CENGINE_H
#include "SFMLGraphics.hpp"
#include "CTextureManager.h"
class CTile; //forward declaration instead of include
class CEngine
{
private:
//Create instance of CTextureManager
CTextureManager textureManager;
//Load textures
void LoadTextures();
//New tile
CTile* testTile;
bool Running; //Is running?
sf::RenderWindow* window; //Create render window
public:
CEngine(); //Constructor
int Execute(); //Execute
bool OnInit(); //On intialization
void GameLoop(); //Main game loop
void Render(); //Render function
void Update(); //Update
};
#endif
其他 2 个标头类似。
另外,_CENGINE_H
不是有效的标识符 - 请注意我如何将其重命名为CENGINE_H
。
相关文章:
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 使用命名空间时出现多个定义错误
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- MSVC 错误:4 个重载中的任何一个都无法转换所有参数类型
- 数百个失败的单元测试
- 输出错误:两个不同编译器上的不同输出:Prime Cryptarithm USACO
- Curl - 发送数百个请求,但一次只能发送四个 - 编程
- 错误:多个文件中的结构声明冲突
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接
- 类错误导致几百个错误
- 将 Windows C++ 项目从 Qt4 移动到 5 会给出数百个看似无关的编译错误
- 链接Qt应用程序时出现数百个"undefined reference"错误
- 链接器不指出错误;多个定义警告指向同一行
- BIO_dump_fp导致数百个valgrind错误
- 以尽可能快的速度访问数百个文件
- 生成错误:12 个重载中没有一个可以转换所有参数类型
- visual C++LNK1120致命错误:1个未解析的外部
- 如果只创建一次,使用数百个线程是否安全?
- 程序特定的OpenGL运行时错误:多个输入缓冲区蒙皮动画