This is my function.
template<class KEY, class T, int (*thash)(const KEY& a)>
HashMap<KEY, T, thash>& HashMap<KEY, T, thash>::operator =(const HashMap<KEY, T, thash>& rhs) {
if (this == &rhs)
return *this;
delete_hash_table(map, bins);
bins = rhs.bins, used = rhs.used;
hash = rhs.hash;
map = this->copy_hash_table(rhs.map, rhs.bins);
std::cout << *this << std::endl;
++mod_count;
std::cout << "DONEZO" << std::endl;
return *this;
}
The only other real functions it calls is delete_hash_table, which does not throw the allocation error (because it's deallocating), and copy_hash_table, which I thought may throw the error, but my std::cout prints just fine.
Just in case, here is my copy_hash_table function.
template<class KEY, class T, int (*thash)(const KEY& a)>
typename HashMap<KEY, T, thash>::LN* HashMap<KEY, T, thash>::copy_list(LN* l) const {
if (l == nullptr)
return nullptr;
return new LN(Entry(l->value.first, l->value.second), copy_list(l->next));
}
template<class KEY, class T, int (*thash)(const KEY& a)>
typename HashMap<KEY, T, thash>::LN** HashMap<KEY, T, thash>::copy_hash_table(LN** ht, int bins) const {
std::cout << "ASSIGNMENT" << std::endl;
LN **to_return = new LN*[bins];
for (int x = 0; x < bins; x++)
to_return[x] = copy_list(ht[x]);
return to_return;
}
Donezo gets printed right before I return. I'm not sure what's causing the error.
Error: std::bad_alloc thrown in test body.