inheriting from a class template

A

Alfonso Morra

if I have a base class A declared as:

template <typename T1, typename T2,
my_enum_1=NONE, my_enum_2=ALL, bool=true>
class A {

....
};


How do I create a child class B?. Can I declare B as :

class B: public A {

} ;


or should it be:

class B: public A<Type1,Type2> {
....
}



Tks
 
P

Pete Becker

Alfonso said:
if I have a base class A declared as:

template <typename T1, typename T2,
my_enum_1=NONE, my_enum_2=ALL, bool=true>
class A {

...
};

A is not a class. It is a template.
How do I create a child class B?. Can I declare B as :

class B: public A {

} ;

No. A base class must be a class. It cannot be a template.
or should it be:

class B: public A<Type1,Type2> {
...
}

If Type1 and Type2 are the names of types, then A<Type1,Type2> is the
name of a class, and can be used as a base class.
 
R

Ram

Alfonso said:
if I have a base class A declared as:

template <typename T1, typename T2,
my_enum_1=NONE, my_enum_2=ALL, bool=true>
class A {

...
};
The line
my_enum_1=NONE, my_enum_2=ALL, bool=true>

doesn't achieve anything, perhaps you might like to say
template <typename T1, typename T2,
my_enum_1 e1=NONE, my_enum_2 e2=ALL, bool b=true>
How do I create a child class B?. Can I declare B as :

class B: public A {

} ;


or should it be:

class B: public A<Type1,Type2> {
...
}

You need to specify a type while deriving, even from a template. If B
needs to derive from A for certain types only then you can do like
above where Type1 and Type2 must be those types e.g.

class B: public A<int, double>

However, if you want to make B also generic u can make it a template.

template <typename T1, typename T2
my_enum_1 e1=NONE, my_enum_2 e2=ALL, bool b=true>
class B: public A<T1, T2, e1, e2, b>
{
// ...
};

Ram
 
A

Alfonso Morra

Alfonso said:
if I have a base class A declared as:

template <typename T1, typename T2,
my_enum_1=NONE, my_enum_2=ALL, bool=true>
class A {

...
};


How do I create a child class B?. Can I declare B as :

class B: public A {

} ;


or should it be:

class B: public A<Type1,Type2> {
...
}



Tks

Thanks for the help guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top