[英]Template Class derived from Non-template base class: No access to base class variables?
I have the following class structure: 我具有以下类结构:
class Base {
public:
std::set<Index> openIndices;
Base() {};
};
template<typename lhs_t, typename rhs_t>
class Derived : public Base {
public:
lhs_t &lhs;
rhs_t &rhs;
Derived(lhs_t &_lhs, rhs_t &_rhs) :
Base(),
lhs(_lhs),
rhs(_rhs),
openIndices(std::set_symmetric_difference(lhs.openIndices, rhs.openIndices))
{
}
};
So basicly a template Class Derived
derived from the base class Base
. 因此从根本上讲,是从基类
Base
Derived
的模板类Derived
。 When accessing the member variables ob the baser class I get the following error: 在访问基类的成员变量时,出现以下错误:
test.h:34:88: error: class ‘Derived<lhs_t, rhs_t>’ does not have any field named ‘openIndices’
I am aware of this question : I cannot access the member variables in case my class is derived from a template class. 我知道这个问题 :万一我的类是从模板类派生的,我将无法访问成员变量。 But in my case I am not derived from a template class, still I can't access the member variables.
但是就我而言,我不是从模板类派生的,但仍然无法访问成员变量。 Could anyone tell me why?
谁能告诉我为什么?
You cant initialize member variables of a base class. 您不能初始化基类的成员变量。 You have to provide an appropriate constructor in the base class and call this constructor.
您必须在基类中提供适当的构造函数,然后调用该构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.