开发者

Errors in simple template code

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

int main(){}

The above piece开发者_StackOverflow中文版 of code gives errors

expected nested-name-specifier before 'T'

expected ';' before '*' token

What is wrong with the code sample?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜