[英]Deriving a template class from a non-template base
I'm trying to do have Derived derive from Base: 我试图做Derived派生自Base:
class Base
{
public:
Base() {};
};
template <class T>
class Derived : public Base
{
public:
Derived::Derived()
{
}
};
This gives me the following error: 这给了我以下错误:
error C3254: 'Derived': class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration
错误C3254:'派生':类包含显式覆盖'{ctor}'但不派生自包含函数声明的接口
note: see reference to class template instantiation 'Derived' being compiled
注意:请参阅正在编译的类模板实例化'Derived'的引用
error C3244: 'Derived::Derived(void)': this method was introduced by 'Unknown>' not by 'Base'
错误C3244:'Derived :: Derived(void)':此方法由'Unknown>'引入,而不是'Base'引入
I'm totally new to templates, what simple steps am I missing? 我对模板完全不熟悉,我错过了哪些简单的步骤? This seems like a pretty basic thing.
这似乎是一个非常基本的事情。
You need to omit the "Derived::" prefix. 您需要省略“Derived ::”前缀。 You would only use it to refer to a symbol that was inherited, or injected into the namespace of the class Derived.
您只能使用它来引用已继承的符号,或者将其注入到Derived类的命名空间中。 So the only prefix that makes sense is "Base::" here.
所以唯一有意义的前缀是“Base ::”。 It has nothing to do with templates.
它与模板无关。
class Base
{
public:
Base() {};
};
template <class T>
class Derived : public Base
{
public:
Derived() {}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.