I looked up on Wiki for the keyword typename (http://en.wikipedia.org/wiki/Typename) and it gives an example which typename is required before T::bar
template <typename T>
void foo(const T& t)
{
// declares a pointer to an object of type T::bar
T::bar * p;
}
struct StructWithBarAsType {
typedef int bar;
};
int main() {
StructWithBarAsType x;
foo(x);
}
Why doesn't C++ inspect StructWithBarAsType and find that T::bar is actually a type when generating code for foo(x)? Is it not possible or just an efficiency consideration?