3

This simple inheritance structure works fine

class Parent{
protected:
    int x;
};

class Child : public Parent{
public:
    int func() {return x;}
};

Meanwhile, the code below which is nearly identical doesn't work. Why is this?

template<typename T>class T_Parent{
protected:
    int x;
};

template<typename T> class T_Child : public T_Parent <T>{
public:
    int func() {return x;}
};

EDIT: the error is use of undeclared identifier 'x' despite x being defined in the Parent class

Ace shinigami
  • 1,374
  • 2
  • 12
  • 25

0 Answers0