【问题标题】:Errors in simple template code简单模板代码中的错误
【发布时间】:2010-10-16 07:04:41
【问题描述】:
template <class T>
struct ABC
{
      typedef typename T* pT;     
};

int main(){}

上面的代码给出了错误

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

代码示例有什么问题?

【问题讨论】:

标签: c++ templates typedef typename


【解决方案1】:

关键字typename 禁止用于非限定名称(前面没有::),即使它们是从属的。

C++03 [Section 14.6/5] 说

关键字typename 应仅应用于限定名称,但这些名称不必依赖。

pt 依赖于 T 但这并不重要(在这种情况下)。

删除 typename 以使您的代码编译。

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 2012-02-13
    • 2014-08-16
    • 2011-09-21
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    相关资源
    最近更新 更多