c++ - 有人可以帮助我处理 C++ 模板中的嵌套名称说明符吗?

标签 c++ templates

下面的示例代码有什么问题?它不会在 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/

相关文章:

c++ - 导入父类的所有变量

c++ - 有没有办法为模板函数参数定义一个类型?

c++ - 我可以使用成员变量实例化成员类模板吗?

c++ - Qt Label::setPixmap 不工作

c++ - 为什么 find_one 不能在 MongoDB C++ 中工作?

c++ - C++ 中 int main 中 ofstream 的参数/声明应该是什么?

c++ - 从 std::array 等获取 size_type 的惯用方法

C++ 元编程 doxygen 文档

c++ - 将 char 数组传递给函数

c++ - 为什么这个流缓冲区不工作?