Chris
05-01-2001, 10:05 PM
Can you put the implementation and header file of a child class in a file
other than the one the parent class was declared in??
If so, what is the exact format for the child header file???
example
In file 1
template <class T>
class parent
{
};
In file 2
class child : parent
{
};
Danny Kalev
05-02-2001, 02:38 AM
Chris wrote:
>
> Can you put the implementation and header file of a child class in a file
> other than the one the parent class was declared in??
>
> If so, what is the exact format for the child header file???
>
> example
>
> In file 1
>
> template <class T>
> class parent
> {
> };
>
> In file 2
>
you need to inherit a specialization, i.e., a template instance. Thus
instead of:
> class child : parent
> {
>
> };
you should do:
> class child : parent <sometype>
> {
>
> };
Of course, you can templatize child too, and use sometype as a template
parameter, in other words, you can do the following:
template <class T>
class child: public parent <T>
{
};
When dealing with templates, it's best to implement every member
function within the header file. You don't have to define child and
parent within the same header file. You can #include "parent.h" inside
"child.h". This will work if you provide the definition of parent's
member functions inside parent.h, not in a separate .cpp file.
Danny