So I'm trying ti print out a vector of list of objects I have in a hash table with the following code but I keep getting these errors and I'm not sure why...
SeparateChaining.h: In member function 'void HashTable<HashedObj>::print()':
SeparateChaining.h:165:13: error: need 'typename' before 'std::list<HashedObj>::iterator' because 'std::list<HashedObj>' is a dependent scope
SeparateChaining.h:165:39: error: expected ';' before 'li'
SeparateChaining.h:166:17: error: 'li' was not declared in this scope
SeparateChaining.h: In instantiation of 'void HashTable<HashedObj>::print() [with HashedObj = Symbol]':
Driver.cpp:72:21: required from here
SeparateChaining.h:165:13: error: dependent-name 'std::list<HashedObj>::iterator' is parsed as a non-type, but instantiation yields a type
SeparateChaining.h:165:13: note: say 'typename std::list<HashedObj>::iterator' if a type is meant
Here is the snippet of my class featuring the print function:
class HashTable
{
/// ....
void print()
{
for(int i = 0; i < theLists.size(); ++i)
{
list<HashedObj>::iterator li;
for(li = theLists[i].begin(); li != theLists[i].end(); ++li)
cout << "PLEASE WORK" << endl;
}
/*
for(auto iterator = oldLists.begin(); iterator!=oldLists.end(); ++iterator)
for(auto itr = theLists.begin(); itr!=theLists.end(); ++itr)
cout << *itr << endl;
*/
}
private:
vector<list<HashedObj>> theLists; // The array of Lists
};
And here's how I overload the ostream operator<< (in the Symbol Class):
friend ostream & operator <<(ostream & outstream, Symbol & symbol) //overloaded to print out the the HashTable
{
int num = symbol.type;
string name = symbol.data;
outstream << name << " : " << num << "\n";
return outstream;
}