I was hoping someone would reply :wink:
Why shouldn't this compile?
T is a template type, you don't know what T::mytype is until you know the actual T. But the compiler needs to parse the template code before any template instantiation is done. So the standard dictates that the compiler should assume it's an identifier (function, variable, enum value, whatever) and not a type. You need to tell the compiler it's a typename using the typename keyword:
typename T::mytype a;
The same goes for the template, in my example it's obvious what it should be, but what if the template argument was a value instead of a type, like this:
That could parse as a variable definition or a simple expression: test if the value of t::mytemplate is smaller than 3, and the result of that is smaller than b.
Therefore, next to the typename discussed earlier, you also need to specify a template:
typename T::template mytype<3> b;
Another example: this gives wrong results under VC++ (why?)
I got this:
Seems about right...
Wrong again, func(int) wasn't defined until after
the definition of tfunc. Therefore, it shouldn't be considered in the list of possible overloads to call when tfunc calls func. func(char) should be called twice.