0

I am trying to write some very generic code and faced a problem of inheritance when dealing with template classes. Here is the code:

template <typename T>
class Base
{
public:
    Base(int i, T t):m_i(i),m_t(t){}
    virtual ~Base(){}
protected:
    int m_i;
    T m_t;
};

template <typename T>
class Derived : public Base<T>
{
public:
    Derived(int i, T t):Base<T>(i,t){}
    ~Derived(){}
    void print() { cout << m_i << " " << m_t << endl;}
};

int main()
{
    Derived<double> d(1,2.4);
    d.print();
}

The surprising thing for me is that it does not compile because 'm_i' and 'm_t' were not declared in this scope. Are the inheritance rules not valid in case of template classes? Is there any way to circumvent this issue?

Rebrado
  • 51
  • 9

0 Answers0