#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(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter