Template and inheritance
Solved
jihane jihane
Posted messages
100
Status
Member
-
jihane jihane Posted messages 100 Status Member -
jihane jihane Posted messages 100 Status Member -
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 answer
-
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...
template <typename T> class Parent { } template <typename T> class Child : public Parent<T> { }
--
Trust does not exclude control.-
-
-
-
You would act as if the parent class was not a template...
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> {} -
-