Jump to content
  • Advertisement
Sign in to follow this  
l jsym l

Iterator troubles

This topic is 2563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Im creating an array of lists. I need to be able to iterate through the list for printing and comparison reasons. This code is not completely done by any means so the code I'll be posting is very rough. I'm just getting an error that is saying: "expression must have class type". Im getting this error where im creating my for loop for the iterator. If anyone has any suggestions let me know. Thanks!

#include "LinkingHash.h"



int LinkingHash::getHash( string str )
{
int result = 0;

for ( unsigned int i = 0; i < str.length(); i++ )
{
result = result + ( int( str ) );
}

return result % 13;
}

void LinkingHash::addToHash( string str )
{
hashIndex = getHash( str );

hashTable[hashIndex].push_back( str );
//cout << hashTable[hashIndex].back() << endl;

list<string>::const_iterator it;
for( it = hashTable.begin();
it != hashTable.end();
it++)
{

}

}

void LinkingHash::deleteFromHash( string str )
{
hashIndex = getHash( str );

vector<string> vec;

for( unsigned int i = 0; i < hashTable[hashIndex].size(); i++ )
{
string temp = hashTable[hashIndex].back();
hashTable[hashIndex].pop_back();

vec.push_back( temp );

if ( vec.back() == str )
{
vec.pop_back();
}
}

for( unsigned int i = 0; i < vec.size(); i++ )
{
string temp = vec.back();
vec.pop_back();

hashTable[hashIndex].push_back( temp );

}


}

void LinkingHash::printHashTable()
{
int index = 0;
vector<string> vec;

while( index < SIZE )
{
cout << index << ") ";

/*list<string>::const_iterator Iterator;
for(Iterator = hashTable.begin();
Iterator != hashTable.end();
Iterator++)*/


for( unsigned int i = 0; i < hashTable[index].size(); i++ )
{
string temp = hashTable[hashIndex].back();
hashTable[hashIndex].pop_back();

vec.push_back( temp );


}

for( unsigned int j = 0; j < vec.size(); j++ )
{
string temp = vec.back();
vec.pop_back();

cout << temp << " ";

hashTable[hashIndex].push_back( temp );

}

cout << endl;

index++;
}




}

Share this post


Link to post
Share on other sites
Advertisement
Since your hash table is a [font="Courier New"]list<something_else<string>>[/font], the iterator type should be [font="Courier New"]list<something_else<string>>::const_iterator[/font]. If your compiler supports C++11, the type can be automatically deduced with the [font="Courier New"]auto[/font] keyword.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!