Does Not Name A Type in C++


Question

in C++ when i get an error that says xxxxx does not name a type in yyy.h

What does that mean?

yyy.h has included the header that xxxx is in.

Example, I use:

typedef CP_M_ReferenceCounted FxRC;

and I have included CP_M_ReferenceCounted.h in yyy.h

I am missing some basic understanding, what is it?

1
6
11/19/2009 5:13:55 AM

That seems you need to refer to 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 would be

...error: CP_M_ReferenceCounted does not name a type

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

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

typedef CP_M_ReferenceCounted FxRC;
...

So please check the namespace scope in your .h headers.

5
3/3/2017 6:02:57 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon