從非模板基類派生的模板類:無法訪問基類變量?

[英]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 Derivedderived from the base class Base. When accessing the member variables ob the baser class I get the following error:

所以基本上是從基類Base派生的模板Class Derived。當訪問成員變量ob basr類時,我收到以下錯誤:

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?

我知道這個問題:如果我的類是從模板類派生的,我無法訪問成員變量。但在我的情況下,我不是從模板類派生的,仍然無法訪問成員變量。誰能告訴我為什么?

1 个解决方案

#1


6  

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

您無法初始化基類的成員變量。您必須在基類中提供適當的構造函數並調用此構造函數。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/02/13/720da9363af9d1f9bc1d911c87623b56.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com