 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
zl2k Guest
|
Posted: Thu Aug 17, 2006 9:01 am Post subject: template inheritance |
|
|
hi, all
Suppose I have a template class A
template<class T> class A{...}
Then I have another class B which inherits class A. Should I say
class B: public A{...}
or class B: template<class T> A{...}
or template<class T> class B : public A {...}
or something else? I assume that class A is also a template. But can
class A be a non template class? If yes, how can A handle the different
type of T? Thanks ahead.
zl2k |
|
| Back to top |
|
 |
Frederick Gotham Guest
|
Posted: Thu Aug 17, 2006 9:05 am Post subject: Re: template inheritance |
|
|
template<class T>
class Derived : public Base<T> {
};
--
Frederick Gotham |
|
| Back to top |
|
 |
Thomas J. Gritzan Guest
|
Posted: Thu Aug 17, 2006 9:10 am Post subject: Re: template inheritance |
|
|
zl2k schrieb:
| Quote: | hi, all
Suppose I have a template class A
template<class T> class A{...}
Then I have another class B which inherits class A. Should I say
class B: public A{...}
or class B: template<class T> A{...}
or template<class T> class B : public A {...}
|
Depends.
If you want class B to be a template like class A, then:
template <class T>
class B : public A<T>
{
// ...
};
If you want that class B inherits from a specific class A, say with
template parameter int:
class B : public A<int>
{
// ...
};
--
Thomas |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|