C++向量操作错误

use*_*378 3 c++ vector

我目前在我的程序中使用了一个向量,我得到了一些奇怪的错误,这些错误只在我开始使用该类后出现.

错误是:

1>MyCloth.obj : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "public: unsigned int & __thiscall std::vector<unsigned int,class std::allocator<unsigned int> >::operator[](unsigned int)" (??A?$vector@IV?$allocator@I@std@@@std@@QAEAAII@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW
1>D:\Licenta\Project\IOPBTS\Debug\IOPBTS.exe : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)

我的代码是:

在头文件中:

#undef vector
#include <vector>

void findPieceVertices(NxU32 selectedVertex); 
bool checkVertexExistsInClothPieceElements(int vertex);
void findVertexTriangles(NxU32 vertex);
std::vector<NxU32> clothPieceElements;
Run Code Online (Sandbox Code Playgroud)

在cpp文件中:

bool MyCloth::checkVertexExistsInClothPieceElements(int vertex)
{
for(int i=0;i<clothPieceElements.size();i++)
    if(clothPieceElements[i]==vertex)
        return true;
return false;
}

void MyCloth::findVertexTriangles(NxU32 vertex)
{
NxMeshData data = mCloth->getMeshData();
NxU32* vertices = (NxU32*)data.indicesBegin;
NxU32 aux = 0;

for(int i=0;i<(mInitNumVertices-1)*3;i+=3)
{
    if(*vertices == vertex || *(vertices+1) == vertex || *(vertices+2) == vertex)
    {
        if(!checkVertexExistsInClothPieceElements(*vertices))
            clothPieceElements.push_back(*vertices);
        if(!checkVertexExistsInClothPieceElements(*(vertices+1)))
            clothPieceElements.push_back(*(vertices+1));
        if(!checkVertexExistsInClothPieceElements(*(vertices+2)))
            clothPieceElements.push_back(*(vertices+2));
    }
    vertices = vertices + 3;
}
Run Code Online (Sandbox Code Playgroud)

}

void MyCloth::findPieceVertices(NxU32 selectedVertex)
{
clothPieceElements.push_back(selectedVertex);
int i=0;
while(i<clothPieceElements.size())
{
    findVertexTriangles(clothPieceElements[i]);
    i++;
}

}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我在互联网上找到了一些东西,它说我使用的文件是在发布模式下编译的,我也应该这样做.问题是,如果我在发布模式下编译,这些错误就会消失,但我的程序找不到非常重要的非C库,这是由VCC目录 - >包含目录中添加的路径指向的.

有谁知道为什么会出现这个错误?或者它意味着什么

编辑:另外,有人能告诉我在调试或发布模式下构建的区别吗?

Mik*_*ail 5

好像你弄乱了CRT库.Debug和Release版本之间有两个主要区别:

  • 使用不同的CRT库
  • 对代码进行了不同的优化

两者都与您的问题有关.首先,检查此评论.libcmtd.lib您的链接线似乎遗漏了.检查您是否从链接器 - >输入选项下的链接中排除这样的重要库.

该函数__CrtDbgReportWvector::operator[]在Debug构建中执行的某些运行时检查有关.由于在发布版本中禁用了这些检查,因此在发行版中没有此错误.

还要确保在C/C++ - >代码生成选项下使用正确版本的CRT.您应该具有用于​​Debug配置的调试版本(动态或静态)以及用于Release配置的发行版本.

没有任何经验,这是一个棘手的问题.如果您有可能,我建议您从默认模板创建一个新项目,并将所有文件添加到此新项目中,以确保默认设置所有设置.