Please help!! I\'m getting the following error in C++ that i cannot figure out.
ID: 3859955 • Letter: P
Question
Please help!! I'm getting the following error in C++ that i cannot figure out. The error is pointing to the line in bold below (though i realize that it may be a symptom iof an error elsewhere in the program):
cannot convert 'std::list<_Tp, _Alloc>::size<std::basic_string<char>, std::allocator<std::basic_string<char> > >' from type 'std::list<std::basic_string<char> >::size_type (std::list<std::basic_string<char> >::)() const {aka unsigned int (std::list<std::basic_string<char> >::)() const}' to type 'int'
template <class DataType>
void HashTable<DataType>::split(int i, int p)
{
int count = V[i].size();
while (count > p)
{
string elementToMove = V[i].back();
int moveTo = splitHelp(i, p); //helper variable to find next available list whose size is less than p
V[moveTo].push_back(elementToMove); //add string to new location
V[i].remove(elementToMove);
count = V[i].size;
}
}
Explanation / Answer
Hi,
I have fixed the syntax issue and highlighted the code changes below
template <class DataType>
void HashTable<DataType>::split(int i, int p)
{
int count = V[i].size();
while (count > p)
{
string elementToMove = V[i].back();
int moveTo = splitHelp(i, p); //helper variable to find next available list whose size is less than p
V[moveTo].push_back(elementToMove); //add string to new location
V[i].remove(elementToMove);
count = V[i].size();
}
}