Oh crap! I think I might have just figured out why typename is required...
After re-reading the error produced by the following code:
Code:
#include <iostream>
#include <list>
using namespace std;
template <class T>
class A { };
template <class T>
class B {
B() { std::list< A< T > >::const_iterator i; }
};
int main(void) {
B<int> a();
return 0;
}
My compiler is gcc 4.1.3, and the error is
Code:
test.cpp: In constructor ‘B<T>::B()’:
test.cpp:11: error: expected `;' before ‘i’
It looks like the compiler (by default) assumes that A::B is referring to a member variable in A, but then it sees 'i' right after and doesn't know what to do with it, kind of like this example:
So typename is required to override the default assumption of the compiler.
Hey cool, I think I just answered my own question.