The missing "typename" error is very common. It suddenly appeared on compilers that follow the ANSI C++ spec concerning names within templates.
YourSurrogateGod, the explanation for your latest errors are simple:
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
std::list<T>::iterator it; // error, but not on older compilers
};
The problem with the second line is fundamental -- the compiler doesn't know if "iterator" is a type, or a static member variable of std::list<T>, so the compiler throws its hands in the air and gives you an error. This makes sense for the compiler to give you an error, since to specify a static member, you use the "::" (scope resolution operator), therefore the ambiguity.
To tell the compiler that "iterator" is a typename and not a static member of std::list<T>, you use the "typename" qualifier.
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
typename std::list<T>::iterator it; // OK
};
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.
Regards,
Paul McKenzie