That's typename not template. ;)
Printable View
That's typename not template. ;)
Hooray, I'm retarted today :rolleyes: .Quote:
Originally Posted by wien
On the bright side it compiled, but I got a segmentation fault right after I printed out the (before the duplicates were removed.)
I've come across this issue before, though it did not take me much effort to resolve it... my compiler, Dev-Cpp 4.9.9.0, actually pointer out what the error was and instructed, in the error message, to add typename.Quote:
You will come across this again, especially if you use Visual C++ 7.x, Dev-C++/MingW, or any ANSI compliant compiler. The problem with the book is that the syntax of leaving out the "typename" worked for many compilers up until recently. So give the book a chance by fixing this problem. I have had to "fix" many header files when compiling under a newer compiler, just for this error alone.
There are a few posts on CodeGuru in this forum and in the Visual C++ forum where persons were getting the very same error you're getting, and couldn't understand why. It is one of the toughest errors to figure out if you are not aware of this issue.
Actually, it's while the duplicates are being removed. You're incrementing curr inside the second while-loop. That way you go out of bounds in a hurry.Quote:
Originally Posted by YourSurrogateGod
Code:template <typename T>
void remove_duplicates(list<T> & a_list)
{
T curr_value;
typename list<T>::iterator curr;
typename list<T>::iterator p;
curr = a_list.begin();
while(curr != a_list.end())
{
curr_value = * curr;
p = curr;
p++;
while(p != a_list.end())
{
if((* p) == curr_value)
{
a_list.erase(p++);
}
else
{
p++;
}
curr++;// Move this one scope down!
}
}
}
Well that's carelesness on my part. I'm pretty tired right now. Thanks for your help :) .Quote:
Originally Posted by wien