下面的示例代码有什么问题?它不会在 GCC 中编译。为什么?
template <class TA>
struct A
{
template <class TAB> struct B;
};
template <class TC>
struct C {};
template <class TD>
struct D
{
template <class TTD> class T {};
};
template<class TA>
template<class TBA>
struct A<TA>::B : C<typename D<TA>::T<TBA> >
{
int foo;
};
GCC 4.3.4 输出:
error: template argument 1 is invalid
error: expected `{' before ‘>’ token
error: expected unqualified-id before ‘>’ token
最佳答案
Clang 的错误信息更有帮助:
error: use 'template' keyword to treat 'T' as a dependent template name
struct A<TA>::B : C<typename D<TA>::T<TBA> >
^
template
有关更多信息,请考虑阅读 Stack Overflow C++ 常见问题 "Where and why do I have to put “template” and “typename” on dependent names?"
关于c++ - 有人可以帮助我处理 C++ 模板中的嵌套名称说明符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5752215/