Errors in the code of a simple template

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

int main(){}

The above code part gives errors

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

What is wrong with the sample code?

+5
source share
1 answer

The keyword is typenameprohibited for unqualified names (those that are not preceded ::), even if they are dependent.

C ++ 03 [Section 14.6/5] says

The typename keyword should only apply to qualified names , but these names should not be dependent.

pt depends on T, but it does not matter (in this context).

Delete typenameto compile your code.

+9
source

All Articles