typename
来自cppreference.com
[编辑] 指定模板的类型参数
在 template 的参数列表中 typename 和 class 是可以互换使用的,用来指定类型参数。虽然它们对编译器来讲没有区别,Alexandrescu 推荐当期望的模板参数是一个 class 或 struct 时使用 class 而在其他情况下使用 typename。 这样做的目的纯粹是为了增加程序的可读性。
[编辑] 消除依赖性名字的二义性
关键词 typename 也可以用来指明模板中的 dependent name 引用的是一个类型。
struct Foo { typedef int Type; }; template<class T> struct Bar { typedef typename T::Type BarType; // In a typedef void baz() { typename T::Type instance; // In a declaration } }; typedef Bar<Foo> FooBar;