简体   繁体   English

C ++错误C2447? 我错过了什么

[英]C++ Error C2447? What am I missing

I don't know if I'm going crazy, or just that everything I've read on this error doesn't apply to my situation. 我不知道我是否会发疯,或者只是我读过的关于这个错误的一切都不适用于我的情况。 But I'm getting these errors when I compile my project: 但是在编译项目时我遇到了这些错误:

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?)

So, I Google'd the error, and everyone said this is caused by things like extra and/or missing semicolons and brackets. 所以,我谷歌的错误,每个人都说这是由额外和/或缺少分号和括号等因素引起的。 But I've looked over my code a lot (there's not very much!) and I don't see any of that, unless of course, as I previously suggested, I'm going crazy... 但是我已经仔细查看了我的代码(不是很多!)而且我没有看到任何这些,除非当然,正如我之前建议的那样,我会发疯...

Game.h Game.h

#ifndef _SBE_CGAME_
#define _SBE_CGAME_

class CGame
{
public:
    CGame();
    ~CGame();

    void DoLoop();
};
#endif //_SBE_CGAME_

Game.cpp Game.cpp

#include "base.h"

extern CGame* m_gGame;

CGame::CGame()
{
    //
}

~CGame::CGame()
{
    //
}

public void CGame::DoLoop()
{
    SwapBuffers(hDC);
}

Base.h 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 Globals.cpp

#include "base.h"

//=================================================================================
// Here is where we define all the global variables
//=================================================================================
CGame* m_gGame = new CGame();

What am I overlooking? 我在俯瞰什么? I will admit, its been a while since I've programmed C++, but I reread class definition articles and all sorts of things. 我承认,自从我编写C ++以来已经有一段时间了,但我重读了类定义文章和各种各样的东西。 I have this not-so-strange feeling that its going to be something very silly, that I should have seen. 我有这种不那么奇怪的感觉,它应该是非常愚蠢的,我应该看到的。

In Game.cpp: 在Game.cpp中:

~CGame::CGame()

should be 应该

CGame::~CGame()

And drop the public keyword on the definition of CGame::DoLoop . 并将public关键字放在CGame::DoLoop的定义上。

You need to write CGame::~CGame() instead of ~CGame::CGame() for the destructor. 你需要为析构函数编写CGame::~CGame()而不是~CGame::CGame() It's always the class name first ( CGame ) and only then the member name ( ~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_

Why are you only include-guarding part of this file? 为什么你只是包含这个文件的一部分?

#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_

Anyway, my guess is something weird in Properties.h or Renderer.h 无论如何,我的猜测在Properties.h或Renderer.h中是奇怪的

you have mis-declared your destructor 你误解了你的析构函数

it should be 它应该是

CGame::~CGame()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM