#include <iostream> using std::cout; using std::endl; template <typename T> class IteratorFacade { public: using Type = T; }; template <typename T> class Iterator : public IteratorFacade<T> { public: using _Type = T; static Type test() { return 1; } }; int main() { cout << Iterator<int>::test() << endl; return 0; } 在以上代码中,MSVC 16.9 可以通过测试,GCC 10 不可以通过测试,在一个更复杂的 代码中,MSVC 和 GCC 均会因为同样原因无法通过编译。GCC 报错原因是 17:12: error: ‘Type’ does not name a type; did you mean ‘_Type’? 也就说Type这个类型并没有继承到 Iterator 类中,但是如果将 test()函数声明中的 Type 改成 Iterator::Type,两个编译器均可以通过编译,我想问下,为什么以上代码通不过编译呢?如果不用模板或者子类不用 using 上面代码均是可以正常编译运行的。
