[英]C++ Error C2447? What am I missing
我不知道我是否会发疯,或者只是我读过的关于这个错误的一切都不适用于我的情况。 但是在编译项目时我遇到了这些错误:
1>f:\program files\testengine\testengine\testengine\game.cpp(10) : error C2061: syntax error : identifier '{ctor}'
1>f:\program files\testengine\testengine\testengine\game.cpp(11) : error C2143: syntax error : missing ';' before '{'
1>f:\program files\testengine\testengine\testengine\game.cpp(11) : error C2447: '{' : missing function header (old-style formal list?)
1>f:\program files\testengine\testengine\testengine\game.cpp(15) : error C2059: syntax error : 'public'
1>f:\program files\testengine\testengine\testengine\game.cpp(16) : error C2143: syntax error : missing ';' before '{'
1>f:\program files\testengine\testengine\testengine\game.cpp(16) : error C2447: '{' : missing function header (old-style formal list?)
所以,我谷歌的错误,每个人都说这是由额外和/或缺少分号和括号等因素引起的。 但是我已经仔细查看了我的代码(不是很多!)而且我没有看到任何这些,除非当然,正如我之前建议的那样,我会发疯...
Game.h
#ifndef _SBE_CGAME_
#define _SBE_CGAME_
class CGame
{
public:
CGame();
~CGame();
void DoLoop();
};
#endif //_SBE_CGAME_
Game.cpp
#include "base.h"
extern CGame* m_gGame;
CGame::CGame()
{
//
}
~CGame::CGame()
{
//
}
public void CGame::DoLoop()
{
SwapBuffers(hDC);
}
Base.h
#include <windows.h> // Header File For Windows ==NEEDS TO COME BEFORE GL.H AND GLU.H==
#include <gl\gl.h>
#include <gl\glu.h>
#include "Properties.h"
#include "Game.h"
#include "Renderer.h"
#ifndef _SBE_BASE_
#define _SBE_BASE_
extern CGame* m_gGame;
#endif //_SBE_BASE_
Globals.cpp
#include "base.h"
//=================================================================================
// Here is where we define all the global variables
//=================================================================================
CGame* m_gGame = new CGame();
我在俯瞰什么? 我承认,自从我编写C ++以来已经有一段时间了,但我重读了类定义文章和各种各样的东西。 我有这种不那么奇怪的感觉,它应该是非常愚蠢的,我应该看到的。
在Game.cpp中:
~CGame::CGame()
应该
CGame::~CGame()
并将public
关键字放在CGame::DoLoop
的定义上。
你需要为析构函数编写CGame::~CGame()
而不是~CGame::CGame()
。 它始终是类名( CGame
),然后是成员名( ~CGame
)。
#include <windows.h> // Header File For Windows ==NEEDS TO COME BEFORE GL.H AND GLU.H==
#include <gl\gl.h>
#include <gl\glu.h>
#include "Properties.h"
#include "Game.h"
#include "Renderer.h"
#ifndef _SBE_BASE_
#define _SBE_BASE_
extern CGame* m_gGame;
#endif //_SBE_BASE_
为什么你只是包含这个文件的一部分?
#ifndef _SBE_BASE_
#define _SBE_BASE_
#include <windows.h> // Header File For Windows ==NEEDS TO COME BEFORE GL.H AND GLU.H==
#include <gl\gl.h>
#include <gl\glu.h>
#include "Properties.h"
#include "Game.h"
#include "Renderer.h"
extern CGame* m_gGame;
#endif //_SBE_BASE_
无论如何,我的猜测在Properties.h或Renderer.h中是奇怪的
你误解了你的析构函数
它应该是
CGame::~CGame()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.