gpt4 book ai didi

c++ - 应用程序在 std::vector::insert 上崩溃

转载 作者:行者123 更新时间:2023-12-02 04:21:34 30 4
gpt4 key购买 nike

我的应用程序在我正在处理的应用程序中的以下行崩溃:

struct PointIndex
{
int PointNr;
};
struct PointIndex PI = { 0 };
std::vector<PointIndex> MyVec;
MyVec.insert( MyVec.begin(), PI );

所示代码已大大简化(例如,MyVec 实际上是 C 数据结构的成员,直到最近它还是 POD,但其中的一些指针已更改为 vector 以安抚 Coverity) ,但我正在使用的应用程序非常大,现在,我希望能得到一些关于可能出现问题的提示。

Visual Studio 2010 将其显示为调用堆栈:

MyAppl.dll!std::_Vector_const_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > >::operator+=(int _Off=-1)  Line 157 + 0x15 bytes   C++
MyAppl.dll!std::_Vector_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > >::operator+=(int _Off=-1) Line 359 C++
MyAppl.dll!std::_Vector_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > >::operator-=(int _Off=1) Line 371 C++
MyAppl.dll!std::_Vector_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > >::operator-(int _Off=1) Line 376 + 0xc bytes C++
MyAppl.dll!std::vector<PointIndex,std::allocator<PointIndex> >::emplace<PointIndex &>(std::_Vector_const_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > > _Where={PointNr=??? }, PointIndex & _Val={...}) Line 689 + 0x4a bytes C++
MyAppl.dll!std::vector<PointIndex,std::allocator<PointIndex> >::insert<PointIndex &>(std::_Vector_const_iterator<std::_Vector_val<PointIndex,std::allocator<PointIndex> > > _Where={PointNr=??? }, PointIndex & _Val={...}) Line 675 + 0x3b bytes C++

崩溃时 vector 为空,但从我看来,对于空 vector 和插入,begin 应该与 end 相同> 使用 end 迭代器与 push_back 相同。

我四处寻找遇到类似问题的人,我能找到的最接近的是 c++ std::vector.insert crashes on debug but works on release ,我已经检查了整个解决方案中对 memset 的调用,但没有找到任何与该库相关的内容。

非常感谢任何/所有见解。

最佳答案

您使用动态链接(例如/MD)还是静态链接(例如/MT)?当您在dll和应用程序中都有内存操作(例如在dll中分配内存并在应用程序中删除它)时,两者都应该使用动态链接进行编译。要更改链接,请转到属性页 - 代码生成 - 运行时库

关于c++ - 应用程序在 std::vector::insert 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17115327/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com