C++ 错误 C2065:未声明的标识符

c++ error C2065: undeclared identifier

本文关键字:标识符 未声明 错误 C2065 C++      更新时间:2023-10-16

>----EDIT找到解决方案,类的命名空间错误。这篇文章可以作为一个例子

得到这个错误,所以我对我到底做错了什么感到困惑。在某些方面.cpp我声明:

。.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
  }
}

标题1.hpp

namespace upr
{
class classW
   {
        //things
   }
}

标头2.h

namespace wre
{
   class classQ
   {
      //things
   }
}

为什么它看不到这个类W?因此,它1的大小未知...所以两个愚蠢的错误。

类Q - 没有问题。

这里有什么意义,有人知道吗?(我在各种命名空间上运行,如有必要,我可以将其添加到这篇文章中)

我想你在做什么是:

标头1.h

namespace N{
  class classW{ };
}

标头2.h

namespace M{
  class classQ{ };
}

一些.cpp

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

这里,你会得到未定义的classW/classQ错误,因为编译器无法从全局命名空间中找到classW/classQ。

您可以实现一些.cpp例如:

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

但这都是我的猜测,需要查看更多代码才能看到代码中真正发生的事情。