struct MyType {
int somedata;
#ifdef HAS_INDEX
int index;
#endif
}
当我向向量添加实例时,当第一次重新分配时,程序挂起:
vector<MyType> myData;
myData.reserve(4);
myData.push_back(MyType{0,0});
myData.push_back(MyType{0,1});
myData.push_back(MyType{0,2});
myData.push_back(MyType{0,3});
myData.push_back(MyType{0,4});
我在之前的行上设置了一个断点,然后逐步完成了附加的过程。当旧的向量存储被释放时,破坏向量的函数似乎在Microsoft Visual Studio 2015编译器的xmemory0处进入无限循环:
template<class _Alloc,
class _Ptr = typename _Wrap_alloc<_Alloc>::pointer> inline
void _Destroy_range1(_Ptr _First, _Ptr _Last, _Wrap_alloc<_Alloc>& _Al, false_type)
{
for (; _First != _Last; ++_First)
_Al.destroy(_Unfancy(_First));
}
(为了清晰起见,对问题进行了编辑,以显示问题)