Does Not Name A Type in C++

70,853

Solution 1

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.

Solution 2

The inclusion of the CP_M_ReferenceCounted type is probably lexically AFTER the typedef... can you link to the two files directly, or reproduce the problem in a simple sample?

Solution 3

Although possibly unrelated to OP's original question... this is an error I just had and shows how this error could occur.

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

For example:

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

Then GetName() must be defined as:

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

not

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

Otherwise the compiler will come back with the error:

error: 'TypeName' does not name a type
Share:
70,853

Related videos on Youtube

JT.
Author by

JT.

Updated on September 14, 2020

Comments

  • JT.
    JT. over 3 years

    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?

    • Martin York
      Martin York over 14 years
      The full error message at a minimum. Preferably some code that generates the error.
    • Alex Martelli
      Alex Martelli
      and how's CP_M_ReferenceCounted defined in its .h? "Does not name a type" suggests it does not name a type (maybe some namespace issue...?)
  • skittlebiz
    skittlebiz over 4 years
    If this was indeed your problem, make sure you <make> clean before you try compiling again, so that the old define macro is cleared out.
  • skittlebiz
    skittlebiz about 2 years
    I would recommend instead replacing CP_M_ReferenceCounted with Yyy::CP_M_ReferenceCounted. The "using" keyword is applied globally to the file and is therefore generalizing what actually needs it. Prepending CP_M_ReferenceCounted with Yyy:: improves readability and suggests to other developers that you are aware CP_M_ReferenceCounted has been defined in that namespace (the namespace of Yyy), and might also help them understand the scope of such a typedef in that any other source code that uses it (especially outside of this source file) might also need to prepend this namespace.

Related