Hey, guys. I'm trying to figure this out. I have a implemented hash table, a vector of lists of pointers to objects, and I'm trying "dump", i.e. go through and print the whole table. I'm just not sure how to iterate through the vector until a list is found, then iterate through the list and print each object and print each object. Any help is very appreciated.
I actually have another problem, sort of on this same topic.
I need to overload the extraction operator<< for the template class above, and print that iterator, problem is the list item it's pointing to is a pointer to an object.
The stream operator you have right now doesn't make sense for the hashTable, you won't know what type T is so you cant overload the stream operator for T. For my examples above T needs to have operator<< overloaded. If you want something like
1 2 3
hash_table h;
...
cout << h;
Then the operator declaration should look like friend ostream& operator<<(ostream& os, const hashTable& RHS); with a possible implementation of
1 2 3 4 5 6 7 8 9 10 11
ostream& operator<<(ostream& os, const hashTable& RHS)
{
for(auto& lst : RHS.table)
{
for(auto i : lst)
{
os << i << ", ";
}
os << endl;
}
}
i need to be able to use dump() to iterate through the table and use << to print each object stored. The lists themselves hold a pointer ( the type is of an abstract base class) to object (derived class)