zl2k wrote:
hi, all
Suppose I have a template class A
template<class Tclass A{...}
No, that's a class template. A is not a class. A<intand A<charare
classes.
Then I have another class B which inherits class A. Should I say
Same problem, you can have a class B<intwhich inherits from A<int>
but
remember that A is not a class.
class B: public A{...}
or class B: template<class TA{...}
or template<class Tclass 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.
template B<Tcan inherit from any class. When you instantiate it, you
have
a type for parameter T. Thus, you can also instantiate template A<Tas
a
base class, or A<std::pair<T,T, or std::ostream. The base class
doesn't
have to be a template instantiation. In fact, it often isn't. The base
class has
no more need to "handle" T as any member of B has. Only your design
will
tell you whether the base class needs to know about T, and how. (E.g.
it
might be a non-template class with a templated contructor)
Regards,
Michiel Salters