#include <iostream>
#include <string>
#include <vector>
struct Type{
typedef std::string strType;
using intType = int;
};
struct Container{
using vecIterType=std::vector<int>::iterator;
};
// 当一个依赖于模板参数的名称代表的是某种类型的时候,就必须使用typename
template<typename T, typename U>
struct Person{
// T::strType str; //error , 编译器会理解为strType是T的static成员变量、枚举变量
// T::intType ivar;
typename T::strType str; // 前面加上typename让编译器理解strType是一个类型
typename T::intType intvar;
typename U::vecIterType it;
};
void Test(){
Person<Type, Container> p;
}
int main()
{
Test();
}
02-25
1994

05-19