C3646 and C4430 due to header file hierarchy?

2019-09-24 09:01发布

问题:

I'm faced with two compilation errors: C3646 and C4430. Let me show you:

I'm referring to this header file:

Timer.h

class Timer {
}

This piece of source code is working fine (in a header file):

#include "Timer.h"
class Something{
    Timer timer_;

This piece of source code is not working (in another header file):

class Something_else : public Singleton<Something_else> {
    friend Singleton<Something_else>;
    Timer getDebuggerTimer;

The compilation errors I get are the mentioned ones:

C3646 'getDebuggerTime': unknown override specifier

C4430 missing specifier - int assumed.

I have tried to include the mentioned header file Timer.h but this is making things even worse (I believe this file is already included via the other include entries).

Why is the compiler expecting override specifiers? (As far as I know there's no need for them, I'm just adding a property to a class?)

On the other places where it's used, the value is filled in in the constructor of the corresponding class (also in the header file). Does this have any impact on this issue?

For your information: the Singleton is used for implementing the corresponding design pattern.

An extra remark: the issue (at first sight) seems not to be related to namespaces.

回答1:

Meanwhile I've understood the root cause of the problem:

As mentioned, in the source code (header file), there's written:

Timer getDebuggerTimer;

Visual Studio's editor accepts this line of source code (no red waves under the word Timer), and while pressing F12 I get into the file Timer.h, where the mentioned class is defined.

However, the compiler does not seem to agree: the compiler does not find the definition of the Timer class in the header file "Timer.h", but instead of saying identifier not understood, he gives that strange compilation message.

How did I find this out?

I've replaced Timer getDebuggerTimer by BlablaTimer getDebuggerTimer. When doing that the editor showed the hint identifier "BlablaTimer" is undefined but the compiler kept on giving the same compiler errors C3646 and C4430.

I'm now digging further in order to know how I can solve this issue, but I do believe that a simple undefined identifier should not be shown as some weird unknown override specifier by the compiler.