gpt4 book ai didi

c++ - Intel Inspector XE 2012 警告 #12367 - 传递给 vector::erase() 的迭代器参数切片

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:29 25 4
gpt4 key购买 nike

运行 Build | 时收到警告 #12367为英特尔静态分析构建解决方案,但我看不到我的代码有问题。有人有想法吗?

warning #12367: slicing of object passed as actual argument 2 in call "std::_Vector_iterator > > std::vector >::erase(std::_Vector_const_iterator > >)" occurs due to implicit type conversion

 pragma warning(suppress: 4995)
#include <vector>

class __declspec(dllexport) MxPluginLib //nothing special here, not derived class etc
{
public:
// ...
private:
// ... nothing special here

};


class __declspec(dllexport) MxPluginManager
{
public:
//...
private:
#pragma warning(suppress: 4251)
std::vector<MxPluginLib *> _Libs;

};

bool MxPluginManager::DeleteNextUnselected()
{
bool erased = false;
size_t cnt = _Libs.size();
if (cnt > 0 )
{
for (size_t x = 0; x < cnt; x++)
{
if (_Libs[x]->GetSelection() == false)
{
delete _Libs[x];
_Libs[x] = '\0';
_Libs.erase(_Libs.begin()+x); //THIS IS WHERE THE WARNING IS GENERATED
erased = true;
break;
}
}
}
return erased;
}

最佳答案

在我看来唯一奇怪的是

_Libs[x] = '\0';

这可能会让分析器认为您存储的是字符而不是指针。由于无论如何您都在删除该元素,因此您实际上并不需要它 - 将其删除,看看它是否能解决您的问题。

关于c++ - Intel Inspector XE 2012 警告 #12367 - 传递给 vector::erase() 的迭代器参数切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13512802/

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