我正在尝试将我的数组复制到一个更大的数组中,然后删除旧数组以进行清理。该类有一个int
和一个指针,并覆盖析构函数以确保它不会在我可以删除指针时删除delete []
。但我的delete []
. 我= new field[1000];
用来初始化数组。
我明白"Collections.exe has triggered a breakpoint."
了,但断点不是我的。
inline void _resize(unsigned int newTableSize, bool _trimCalled){
if (newTableSize < tableSize && _trimCalled == false) {
_trim();
return;
}
field* newTable = new field[newTableSize];
for (unsigned int x = 0; x < newTableSize; x++)
newTable[x] = table[x];
tableSize = newTableSize;
delete[] table;
table = newTable;
}
inline void _trim(){
// compact the table
// fill in from the end of the table
for (int x = tableSize; !emptyPlaces.empty() ; x--){
if (table[x].used = true){
table[emptyPlaces.top()] = table[x];
emptyPlaces.pop();
}
}
// trim the excess
_resize((unsigned int)(usedFields * 1.1 + 10), true);
template<typename key, typename object> class DictonaryArray {
struct field{
field(){ this->key = 0; this->_object = nullptr; this->used = false; }
field(key _key, object __object){;
key = _key;
_object = new object();
*_object = __object;
this->used = true;
}
~field(){
}
key key;
object* _object;
bool used;
};