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
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
is not a class. 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>
. That's what you need:
SubClass1(OtherClass<T> const& class1,
OtherOtherClass<T> const& class2)
: SuperClass<T,S>(class1, class2)
// ^^^^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.