Doesn't indicate type A in C ++

in C ++, when I get an error saying xxxxx does not indicate the type in yyy.h

What does it mean?

yyy.h included the header where xxxx is located.

Example: I use:

 typedef CP_M_ReferenceCounted FxRC; 

and I included CP_M_ReferenceCounted.h in yyy.h

I lack a basic understanding of what it is?

+4
source share
4 answers

It seems you need to reference the namespace accordingly. For example, the following yyy.h and test.cpp have the same problem as yours:

 //yyy.h #ifndef YYY_H__ #define YYY_H__ namespace Yyy { class CP_M_ReferenceCounted { }; } #endif //test.cpp #include "yyy.h" typedef CP_M_ReferenceCounted FxRC; int main(int argc, char **argv) { return 0; } 

The error will be

 ...error: CP_M_ReferenceCounted does not name a type 

But add the line "using namespace Yyy;" fixes the problem as shown below:

 //test.cpp #include "yyy.h" // add this line using namespace Yyy; typedef CP_M_ReferenceCounted FxRC; ... 

Therefore, please check the namespace scope in your .h headers.

+4
source

Enabling type CP_M_ReferenceCounted is possible lexically AFTER typedef ... can you directly link the two files or reproduce the problem in a simple selection?

+1
source

Although perhaps unrelated to the original OP question ... this is the error I just had and shows how this error can occur.

When you define a type in a C ++ class and return it, you need to specify the class in which the type belongs.

For instance:

 class ClassName{ public: typedef vector<int> TypeName; TypeName GetData(); }; 

Then GetName () should be defined as:

 ClassName::TypeName ClassName::GetData(){...} 

not

 TypeName ClassName::GetData(){...} 

Otherwise, the compiler will return with an error:

 error: 'TypeName' does not name a type 
0
source

Yes, try checking namespace .

0
source

All Articles