Search code examples
c++inheritanceclass-template

Can I specify the type of the class template when inherits it into a child class?


Say, I have a parent class template. And want to build several child class upon it. Each child class are typename specific. So can I specify the typename they use when inherit their parent class template?

example of the class definition:

 template <class tName1, class tName2>
 class parent
 {
     tName1 a;
     tName2 b;
     ...
 }

 class child: public parent<int, float>
 {
     ...
 }

Is this code correct?


Solution

  • Yes, I can do it. It seems like each time I call a template in C++, I have to specify its type or make it into another template. In this case it's specifying its type.