0

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?

Chong
  • 933
  • 2
  • 10
  • 28
  • While that doesn't necessarily suffice in C++, a first try (especially with templates) would be to see if it compiles and behaves the way it is supposed. – Christian Rau Nov 13 '13 at 14:12
  • I kind of more into understanding why it works so before trying when programming in C++... For You never know when a misunderstood concept will cause unexpected result. And when it happens, it's very difficult to debug that... – Chong Nov 14 '13 at 11:40

1 Answers1

1

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.

Chong
  • 933
  • 2
  • 10
  • 28
  • 1
    Please don't add "thank you" as an answer. Instead, vote up the answers that you find helpful. – Noel Nov 13 '13 at 11:39