|
|
|
|
|
by pmjordan
6148 days ago
|
|
In C++, the problem becomes so bad that the language designers capitulated in some instances, and you have to tell the compiler if something is a type or an identifier. Haven't tested this example, but you get the point: struct test
{
typedef int bar;
};
template <class T> struct foo
{
typename T::bar x; // if you leave off 'typename', it won't compile
};
foo<test> y;
y.x = 5;
What I don't quite understand is why, if it won't compile in the first place (i.e. there is no ambiguity, just correct or incorrect), you need to specify it in the first place. I suspect it somehow makes compiler implementation easier. |
|