我刚刚更新到 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/