Reputation: 9319
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
. 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?
Upvotes: 5
Views: 8104
Reputation: 11482
You cant initialize member variables of a base class. You have to provide an appropriate constructor in the base class and call this constructor.
Upvotes: 8