C++ 未知重写说明符+;缺少类型说明符
我正在使用Visual Studio 2015 Update 2。 我有两个标题,分别是Error.h和Game.h 错误。h:C++ 未知重写说明符+;缺少类型说明符,c++,visual-studio,visual-studio-2015,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,
#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
我真的很困惑,为什么会出错!?
我还必须说,在头核心.h中,它将再次包含Error.h,但这一定不是问题 我刚刚将ErrInfo struct移动到另一个具有相同include-guard的头文件中,它编译和工作没有问题,我认为这是编译器失败,如果不是,请解释。
String
应该是String
,您是使用命名空间std
?如果不是,则应将字符串声明为std::string
。你能通过提供这两个文件的全部内容来编辑你的帖子吗?@KostasRim不要和std::string混淆,string是我的另一个类,它工作得很好!有两件事(但与您的问题无关):首先,不要使用任何带有前导下划线和大写字母的符号,这些符号在所有作用域()中都是保留的。其次,除非你是被迫的,或者这是学校作业的一部分,否则不要使用自定义字符串类。使用std::string
或您正在使用的框架中的其他字符串类(例如,Qt中的QString
或MFCCString
类)。不要重新发明轮子,它只会以悲伤告终。@暗杀者请编辑这篇文章并提供更多关于这两者的细节files@JoachimPileborg不要重新发明轮子,它只会以悲伤告终
如果我能竖起大拇指,我会的!奇怪的我原以为特定的include-guard会有问题,而名为ErrInfo和Error的全局类型很有可能与某些内容发生冲突,但在保留include-guard名称的同时将它们移动到另一个标题解决问题是很奇怪的。@SebastianRedl是的,我也尝试过一次“#pragma”,但没有成功,有时VisualStudio会变得疯狂
#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
Error C3646 'errError': unknown override specifier
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int