c++ - 如何定义模板的模板化子类?

标签 c++

我刚刚更新到 GCC 4.8.2(从 4.7),现在收到以下代码的警告:

template <class T_base>
class factory {
private:
    template <class T>
    struct allocator : factory {
                    // ^ warning: invalid use of incomplete type 'class factory<T_base>'
    };
};

为了避免警告,我尝试在 factory 之外定义 struct allocator,但现在出现以下错误:

template <class T_base>
class factory {
private:
    template <class T>
    struct allocator;
};

template <class T_base, class T>
struct factory<T_base>::allocator<T> : factory<T_base> {
                     // ^ error: too few template-parameter-lists
};

我做错了什么?上述结构是否有避免警告和错误的语法?

最佳答案

你需要这样拼写:

template <class T_base>
template <class T>
struct factory<T_base>::allocator : factory<T_base>
{
    // ...
};

关于c++ - 如何定义模板的模板化子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21971047/

相关文章:

c++ - 函数模板参数编译错误

c++ - Python 调用 DLL 调用 Python, "WindowsError: exception: access violation reading 0x00000004"

c++ - fatal error C1001 : An internal error has occurred in the compiler (compiler file 'msc1.cpp' , 第 1325 行)

C++ 多重包含的烦恼

c++ - 遍历 C++ 中的字符串列表,出了什么问题?

c++ - 用opencv着色

C++ friend 类无效使用不完整类型 OOP

c++ - 我如何检查迭代器是否到达列表末尾?

c++ - Shape.SetAsBox() 中的断言失败?

python - Cython 中动态大小的对象数组