5

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 Derivedderived 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?

Community
  • 1
  • 1
Haatschii
  • 9,021
  • 10
  • 58
  • 95

1 Answers1

8

You cant initialize member variables of a base class. You have to provide an appropriate constructor in the base class and call this constructor.

Sebastian Hoffmann
  • 11,127
  • 7
  • 49
  • 77
  • 1
    Omg, yea I should have known this! Obviously I was too confused by the templates in my true code. Thanks anyway. – Haatschii Feb 13 '14 at 22:35