好奇的探索者,理性的思考者,踏实的行动者。
Table of Contents:
struct X { typedef int foo; };
struct Y { static int const foo = 123; };
// T::foo的可能是一个类型,也可能是一个变量,这个就存在歧义了
// 可以认为 int * x; 一个变量定义
// 也可以认为 123 * x; 一个乘法表达式
template<class T> void f_tmpl () { T::foo * x; }
c++中这种情况被称为dependent names,
template<typename T>
struct MyType {
using iterator = ...; //c++中这叫做alias template
...
};
template<typename T>
using MyTypeIterator = typename MyType<T>::iterator; // typename必须有
MyTypeIterator<int> pos;
上面的注释说明了:typename MyType