Template and inheritance
Solved
jihane jihane
Posted messages
100
Status
Membre
-
jihane jihane Posted messages 100 Status Membre -
jihane jihane Posted messages 100 Status Membre -
Hello,
Please, can a derived class use the generic type of the base class if the base class is declared as a template
template<class T> NAME OF THE CLASS? In other words, can we use the keyword T instead of the type in the derived class? Thank you for your forthcoming reply :)
Please, can a derived class use the generic type of the base class if the base class is declared as a template
template<class T> NAME OF THE CLASS? In other words, can we use the keyword T instead of the type in the derived class? Thank you for your forthcoming reply :)
1 réponse
Every time you replace your template with a concrete type, you compile a new class, which in turn will compile its parent class. In the end, you will only have concrete types. So there shouldn't be any problem...
--
Trust does not exclude control.
template <typename T> class Parent { } template <typename T> class Child : public Parent<T> { } --
Trust does not exclude control.
I am not sure about the syntax with two templates, but in principle, these two codes should have roughly the same meaning for the child class.
class Parent {} template <typename T> class Child : public Parent {} //------------ template <typename U> class Parent {} template <typename T,typename U> class Child : public Parent<U> {}