Ass*_*siN 3 c++ visual-studio visual-studio-2015
我使用的是 Visual Studio 2015 Update 2。我有两个标头,分别称为 Error.h 和 Game.h。
错误.h:
#ifndef _Error_H
#define _Error_H
#include "Main.h"
#include "Core.h"
#include <Log.h>
#include <CWindows.h>
// ErrorIDs
enum
{
ErrUnknownID = 0,
blah,
blah2,
blah3
};
struct ErrInfo
{
unsigned int eiID;
String strCaption; // String is another class which implemented from std::string which works fine!
String strText;
bool bFixable = false;
};
// Static errors
extern ErrInfo WinNotSupported;
// blah blah
class Error
{
public:
void Initialize();
bool ShowError(ErrInfo ErrorInfo);
BOOL FixError(unsigned int uiErrorID);
// -----------------------------------------
// --------------- Singleton ---------------
// -----------------------------------------
public:
static Error& Instance()
{
static Error instance;
return instance;
}
static Error *InstancePtr()
{
return &Instance();
}
private:
Error()
{
}
public:
Error(Error const&) = delete;
void operator=(Error const&) = delete;
};
#endif // !_Error_H
Run Code Online (Sandbox Code Playgroud)
和 Game.h:
#ifndef _Game_H
#define _Game_H
#include "Main.h"
#include "Error.h"
#include "Core.h"
#include <CWindows.h>
#include <AFile.h>
struct missingfileSt
{
String strFileURL;
String strDLFileName;
String strFileName;
String strChecksum;
long long llSize;
ErrInfo errError; // Many errors here <-
};
struct deletablefileSt
{
String strFileName;
ErrInfo errError; // Many errors here too
};
#define siMissingFiles 7
#define siDeletableFiles 5
class Game
{
public:
void ValidateFiles();
DWORD dwGamePID;
missingfileSt mfMissingFiles[siMissingFiles];
deletablefileSt dfDeletableFiles[siDeletableFiles];
// -----------------------------------------
// --------------- Singleton ---------------
// -----------------------------------------
public:
static Game& Instance()
{
static Game instance;
return instance;
}
static Game *InstancePtr()
{
return &Instance();
}
private:
Game()
{
dwGamePID = 0;
}
public:
Game(Game const&) = delete;
void operator=(Game const&) = delete;
};
#endif // !_Game_H
Run Code Online (Sandbox Code Playgroud)
现在,当我编译时,我从 Game.h 中收到许多错误,所有错误都是:
Error C3646 'errError': unknown override specifier
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)
我真的很困惑,为什么会出错!?另外我必须说,在标头 Core.h 中它将再次包含 Error.h,但这一定不是问题!
已经是一个老问题了,但是对于所有 C++ 新手或那些被迫理解(非常)糟糕的 C++ 编译器消息的人来说,缺少一个有用的答案。
如果您收到“缺少类型说明符”、“未知覆盖”、“未定义类型/类”、“语法错误:(”(对于开始函数参数列表),尽管您包含了正确的头文件,但这表明存在一些循环引用在您的包含层次结构中。如果您有前向声明并且类型仍然是“未知”,情况也是如此。
C++ 中旧包含系统的唯一解决方案是避免s之间的#include循环引用。它是通过将#includes 从头文件移动A.h到A.cpp并通过在 中向前声明类型(或方法)来实现的A.h。如果您不移动#include到A.cpp它,尽管进行了前向声明,仍然可能会失败。
让A.h是一个循环包含在B.h因为B.h已经包含在 中A.h。代替
#include "A.h"
class B {
A a;
}
Run Code Online (Sandbox Code Playgroud)
你可以写
class A;
class B {
A a;
}
Run Code Online (Sandbox Code Playgroud)
并包含A.h在您的 CPP 文件中。
如果仅在 CPP 文件中定义方法,则可以避免方法前向声明的需要。
| 归档时间: |
|
| 查看次数: |
13471 次 |
| 最近记录: |