mercredi 25 mai 2016

How does Inheritance work with templates in c++?

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;}
};

Aucun commentaire:

Enregistrer un commentaire