Visual c++ Studio 2010会无缘无故地显示构建错误
Visual C++ Studio 2010 shows build errors for no reason
显然,我不能在另一个类的公共部分声明一个类的实例。
我有两个类:游戏和ScreenManager。如果我从Game.h中删除以下行,一切都会成功编译:
ScreenManager screenManager;
如果我不这样做,我得到错误。这些是我在构建时得到的错误信息:
1>c:usersdzikudocumentsvisual studio 2010projectstest allegro gametest allegro gamegame.h(29): error C2146: syntax error : missing ';' before identifier 'screenManager'
1>c:usersdzikudocumentsvisual studio 2010projectstest allegro gametest allegro gamegame.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersdzikudocumentsvisual studio 2010projectstest allegro gametest allegro gamegame.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Game.h:
#pragma once
#include"ScreenManager.h"
#include<allegro5allegro.h>
#include<allegro5allegro_image.h>
#include<allegro5allegro_font.h>
#include<allegro5allegro_ttf.h>
#include<allegro5allegro_primitives.h>
class Game
{
public:
static const int WINDOW_WIDTH=800;
static const int WINDOW_HEIGHT=640;
static const int FPS=60;
float FRAME_INTERVAL;
bool isExiting;
float currentTime,prevTime,lag;
ALLEGRO_DISPLAY* display;
ALLEGRO_EVENT_QUEUE* eventQueue;
ALLEGRO_EVENT ev;
ScreenManager screenManager;
Game(void);
~Game(void);
static Game &getInstance();
void initialize();
void gameLoop();
void cleanup();
void update(ALLEGRO_EVENT &ev);
void render(ALLEGRO_DISPLAY* display);
};
和ScreenManager.h:
#pragma once
#include"Game.h"
#include<allegro5allegro.h>
#include<vector>
#include<map>
class ScreenManager
{
public:
ScreenManager(void);
~ScreenManager(void);
void initialize();
void update(ALLEGRO_EVENT &ev);
void render(ALLEGRO_DISPLAY* display);
void unloadContent();
};
我真的不知道发生了什么,从昨天开始我就一直得到类似的错误,在其他项目中也是如此。我一定是做错了什么,但我不知道,所以任何帮助都会非常感激。
你能解释一下为什么标题"ScreenManager.h"
包含标题"Game.h"
吗?
ScreenManager.h:
#pragma once
#include"Game.h"
如果ScreenManager类成员函数使用了类Game的成员函数的一些数据成员,那么你应该将类定义和uts成员函数的定义分开。只在类定义中声明成员函数,它们的实现放在某个单独的模块中。如果你想的话,你可以通过指定函数说明符inline来使它们内联。
或者你可以在屏幕管理器头文件中将Game类声明为
class Game;
和在单独的模块中定义ScreeManager类的成员函数
相关文章:
- Clion显示错误,但可以使用Cmake成功构建代码
- Visual Studio C++ 它只构建选项卡中显示的文件吗?
- 与clang++一起使用的VS代码在构建良好的C++文件中显示错误
- 使用cmake(窗口)构建时不显示Qt资源
- VS 2017 中的 CMake 在构建时不显示构建日志
- ROS2 COLCON构建未在Windows中显示任何错误消息
- 在为C 设置NetBean时,它显示了未连接的构建主机
- 我正在尝试通过CreateProcess()在Sublime Text中打开文件,但是构建显示错误
- 从VS2008升级后,VS2012中的构建项目显示错误
- EclipseCDT显示了一些错误,但该项目已成功构建
- C ++保存mat文件,构建日志显示"undefined reference to 'H5Tget_member_type'....................."
- 为什么由指针和对象构建的局部变量显示不同的输出
- 使用 QThread 显示构建问题的延时
- D3DX11EffectsD.lib 在构建后未显示 (vs2010)
- Eclipse CDT构建控制台输出不显示整个编译器输出
- 为什么当构建显示时 CPU 不会超过 25% "loop parallelized"
- 选择在构建/调试时首先显示源文件(.cpp)
- Visual c++ Studio 2010会无缘无故地显示构建错误
- 增强构建显示默认工具集和版本
- 我如何让Anjuta突出显示我的构建系统(waf)产生的错误/行