[英]member initializer 'SuperClass' does not name a non-static data member or base class
I have a problem with some of my constructors. 我的一些构造函数有问题。 Both subclasses need to get the same classes (no super class), that is why these classes should be initialized in the super class:
这两个子类都需要获得相同的类(没有超类),这就是为什么这些类应在超类中初始化的原因:
template<typename T, typename S>
class SuperClass {
protected:
OtherClass <T> const& _class1;
OtherOtherClass <T> const& _class2;
SuperClass() {
}
SuperClass(OtherClass<T> const& class1, OtherOtherClass<T> const& class2)
: _class1(class1), _class2(class2)
{
// Alternative I tried:
// this->_class1 = class1;
// this->_class2 = class2;
}
I tried to use it through: 我尝试通过以下方式使用它:
template<typename T, typename S>
class SubClass1 : public SuperClass<T, S> {
private:
someFunc() {
return this->_class1.getSomething(); // as an example
}
public:
SubClass1(OtherClass<T> const& class1,
OtherOtherClass<T> const& class2)
: SuperClass(class1, class2)
{
// some definitions
}
}
After that this error shows up: 之后,出现此错误:
member initializer 'SuperClass' does not name a non-static data member or base class
成员初始化程序“ SuperClass”未命名非静态数据成员或基类
I found some people with similar problems, but it did not lead me to the solution. 我发现有些人有类似的问题,但这并没有带我解决问题。 For example: member initializer does not name a non-static data member or base class I did not see many difference there and tried to add an empty constructor like he did.
例如: 成员初始值设定项未命名非静态数据成员或基类,我在那没有看到很多区别,因此尝试像他一样添加空的构造函数。
The error says it all: 错误说明了一切:
member initializer '
SuperClass
' does not name a non-static data member or base class成员初始值设定项“
SuperClass
”未命名非静态数据成员或基类
SuperClass
is not a class. SuperClass
不是类。 It's a class template . 这是一个类模板 。 As such, it's not the base class of your type.
因此,它不是您类型的基类。 The base class is a specific instantiation of the class template:
SuperClass<T,S>
. 基类是类模板的特定实例:
SuperClass<T,S>
。 That's what you need: 那就是你所需要的:
SubClass1(OtherClass<T> const& class1,
OtherOtherClass<T> const& class2)
: SuperClass<T,S>(class1, class2)
// ^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.