为什么 C++“使用 XXX = type”类型别名需要“typename”?

问题描述

声明类型别名时,

using T = XXX;

XXX 只能是一种类型。

如果 XXX 是模板化类的内部类型别名,为什么还需要在 XXX 之前包含“typename”?

例如

template <typename T> struct fred
{
    using T2 = T[2];
};

template <typename U> struct mary
{
    // why is typename necessary here?
    using M2 = typename fred <U>::T2;
    // this does not compile,even though type alias must refer to a type
    // using M2 = fred <U>::T2;
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)