typedef 一个专门的嵌套模板

typedef a specialized nested template

我正在尝试编译一些似乎不再有效的 C++ 的旧 C++ 代码(VS2008 到 VS2015)。我已经设法将问题缩小到如下所示。

class Any { };

class Parent
{
  template < typename anyT>
  class Child { };
};

template< typename parentT >
class Fail
{
  typedef typename parentT::Child<Any>   ChildT;       // 2 errors
  typename ChildT _child;                              // 2 errors
};

我从 Visual Studio 2015 年得到这个编译器错误。

Error   C2059   syntax error: '<'   TemplateTest    d:\programming\templatetest\example.h   12
Error   C2238   unexpected token(s) preceding ';'   TemplateTest    d:\programming\templatetest\example.h   12
Error   C3646   '_child': unknown override specifier    TemplateTest    d:\programming\templatetest\example.h   13
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    TemplateTest    d:\programming\templatetest\example.h   13  

Where and why do I have to put the “template” and “typename” keywords?

typedef typename parentT::template Child<Any>   ChildT;
ChildT _child;