That question title is a mouthful. Basically, I am creating a hash table structure that uses doubly linked lists within a vector. Everything works fine when I create the object using my overloaded constructor, but using the default constructor causes the state of the object to go funky after returning to main.
My constructors:
HashTable::HashTable()
{
HashTable(53);
}
HashTable::HashTable(int tableSize)
{
currentSize = tableSize;
table.resize(tableSize);
}
Setting breakpoints after creating an object
HashTable ht(size); //this works
HashTable ht; //this does not work
Stepping through the code I see that it calls the overloaded constructor fine, but after returning to main and then attempting to use the table (when using default constructor only), the vector's size and the variable currentSize have gone awry.
After creating object, before returning to main:
currentSize = 53
table [size] = 53, [capacity] = 53, empty linked lists fill the vector
When calling ht.hash(value)
in main, the object now has:
currentSize = -858993460
table [size] = 0, [capacity] = 0, linked lists obviously gone.
What would cause the vector to reset itself to 0 and my private int currentSize to go funky, especially since the code paths both work through HashTable(int tableSize)
?