Sunday, August 28, 2011

Iterator for templated STL containers in C++

I realized this today! The following code almost always will give compilation error.
std::vector::const_iterator itr;

And the compilation error (with g++ version 3.4.6) will be as vague as:
error: expected `;' before "itr"

The solution is to just do the following:
typename std::vector::const_iterator itr;