简体   繁体   中英

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 . 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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM