views:

72

answers:

1
template <class T>
struct ABC
{
      typedef typename T* pT;     
};

int main(){}

The above piece of code gives errors

expected nested-name-specifier before 'T'
expected ';' before '*' token

What is wrong with the code sample?

+12  A: 

The keyword typename is forbidden on unqualified names (those not preceded by ::), even if they are dependent.

C++03 [Section 14.6/5] says

The keyword typename shall be applied only to qualified names, but those names need not be dependent.

pt is dependent on T but that doesn't matter (in this context).

Remove typename to make your code compile.

Prasoon Saurav