AA.
AA.

Reputation: 316

Unknown override specifier + missing type specifier

I'm using Visual Studio 2015 Update 2. I have two headers called Error.h and Game.h.

Error.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

And 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

Now, when I compile I get many errors from Game.h and all of them are:

Error C3646 'errError': unknown override specifier
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int

I got really confused, why errors!? Also I must say, in header Core.h it will include Error.h again but it mustn't be problem!

Upvotes: 3

Views: 15025

Answers (2)

ChrisoLosoph
ChrisoLosoph

Reputation: 617

An old question already but a useful answer is missing for all C++ newbies or those who are forced to understand (very) bad C++ compiler messages.

If you get "missing type specifier", "unknown override", "undefined type/class", "syntax error: (" (for a beginning function parameter list) although you included the proper header file then it indicates that there is some circular reference in your include-hierarchy. This is also true if you have a forward declaration and the type is still "unknown".

The only solution with the old include-system in C++ is to avoid circular references between #includes. It's achieved by moving #includes from a header file A.h to the A.cpp and by forward declaring the types (or methods) in A.h. If you don't move the #include to A.cpp it still can fail despite forward declaration.

Let A.h be a circular include in B.h because B.h would already be included by A.h. Instead of

#include "A.h"

class B {
    A a;
}

you can write

class A;

class B {
    A a;
}

and include A.h in your CPP file(s).

You can avoid the need for method forward declarations if you only define methods in CPP files.

Upvotes: 8

AA.
AA.

Reputation: 316

I just moved ErrInfo struct to another header with the same include guard and it compiled and worked without problem, I think it's compiler failure, if it isn't please explain.

Upvotes: 1

Related Questions