简体   繁体   中英

Difference between errors "does not name a type" and "has not been declared"

After a codebase I am working on has been converted automatically from Java to C++ (Yes, yes, I know, not a good idea, but long story made short, it was needed), I have found that in many classes I have the two following errors, related to my ClassNameXXX type:

‘ClassNameXXX’ does not name a type

and

‘ClassNameXXX’ has not been declared

I understand that the casue of the problem is a matter of cyclic inclusions between the ClassNameXXX.h header and others (and I am working hard to resolve that) but I was wondering what is the actual difference between the two error messages (Maybe this would give me some clues for the resolution of the cycles).

Thanks in advance!

'ClassNameXXX' has not been declared

This one, as the name suggests, emited when you are trying to define something that has not been declared, for example if you write void SomeClass::foo(){} without declaring SomeClass first (eg you forgot to #include someClass.h in someClass.cpp). The compiler understands that you are trying to define a member of SomeClass , but fails to find it, and gives you the error.

'ClassNameXXX' does not name a type

This one rises in different circumstances, eg

class MyClassOne
{
    MyClassTwo _member;//error
};

class MyClassTwo
{
};

Here the compiler understands that MyClassTwo is supposed to be the type of _member , but since MyClassTwo is not yet defined at that place, the compiler has no idea that such a type exists, so it tells you that MyClassTwo does not name a type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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