Question

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?

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top