Search code examples
c++classidentifier

c++ error C2065: undeclared identifier


----EDIT Solution found, wrong namespaces for classes. This post may be as an example of that

I get this error and so I am confused what I do wrong exactly. in some.cpp I declare:

.cpp:

#include "header1.hpp"
#include "header2.h"

using namespace wre;
namespace awq
{
  //somethings
  void function()
  {
      std::vector<classW>::iterator it1; //I mean class upr::classW
      std::map<int, classQ> map1; //I mean class pwe::classQ
      //iterations which don't work
  }
}

header1.hpp

namespace upr
{
class classW
   {
        //things
   }
}

header2.h

namespace wre
{
   class classQ
   {
      //things
   }
}

Why it doesn't see this classW? As consequence it1 is of unknown size ... so two stupid errors.

classQ - there is no problem.

What is the point here, anyone knows? (I operate on various namespaces, I can add it to this post if this is necessary)


Solution

  • I guess what you are doing is:

    header1.h

    namespace N{
      class classW{ };
    }
    

    header2.h

    namespace M{
      class classQ{ };
    }
    

    some.cpp

    #include "header1.h"
    #include "header2.h
    std::vector<classW>::iterator it1;
    std::map<int, classQ> map1;
    

    From here, you get undefined classW/classQ error, because compiler can't find classW/classQ from global namespace.

    You could implement some.cpp like:

     #include "header1.h"
     #include "header2.h
     std::vector<N::classW> v1;
     std::vector<N::classW>::iterator it1;
     std::map<int, M::classQ> map1;
    

    But this is all my guessing, need to see more code to see what's really happening in your code.