A
Alfonso Morra
if I have a class template declared as ff:
(BTW is this [below] a partial specialization? - I think it is)
template <typename T1, myenum_1 e1=OK, my_enum_2=NONE>
class A {
public:
A();
virtual ~A() ;
void foo(void);
void bar(const char*) ;
char* foobar(int) ;
// ... lots more methods
private:
T1 *m_obj ;
my_enum1 m_enum1 ;
myenum_2 m_enum2 ;
};
suppose I decide to specialize the above template further as ff:
template<>
class A <MyType, NOT_OK, ALL> {
};
My question are:
1). Do I need to declare (and define) all of the methods as done
previously for the original class template? - I ask this because it
seems terribly ineffecient and error prone - retyping all that code again.
2). If the answer to the above question is yes (i.e. retyping all the
declarations/definitions again), then is there any point at all in
having a generic class (when you know you will have to specialize it?).
It seems a much better design choice would have been to simply use
inheritance in such an instance - is this a valid conclusion to draw?
3). (Assuming that the answer to question 1 is yes) If another
(template) class inherits from my specialized class template A, then I
would (it appears) have to regurgitate code for each of the combinations
of my derived class specializations and the base class specializations!.
It would seem clas template specialization is a very poor design choice
if one knows at the start that one would require specialization of the
class template. Is this a generally true conclusion - or is there some
thing I am missing?
(BTW is this [below] a partial specialization? - I think it is)
template <typename T1, myenum_1 e1=OK, my_enum_2=NONE>
class A {
public:
A();
virtual ~A() ;
void foo(void);
void bar(const char*) ;
char* foobar(int) ;
// ... lots more methods
private:
T1 *m_obj ;
my_enum1 m_enum1 ;
myenum_2 m_enum2 ;
};
suppose I decide to specialize the above template further as ff:
template<>
class A <MyType, NOT_OK, ALL> {
};
My question are:
1). Do I need to declare (and define) all of the methods as done
previously for the original class template? - I ask this because it
seems terribly ineffecient and error prone - retyping all that code again.
2). If the answer to the above question is yes (i.e. retyping all the
declarations/definitions again), then is there any point at all in
having a generic class (when you know you will have to specialize it?).
It seems a much better design choice would have been to simply use
inheritance in such an instance - is this a valid conclusion to draw?
3). (Assuming that the answer to question 1 is yes) If another
(template) class inherits from my specialized class template A, then I
would (it appears) have to regurgitate code for each of the combinations
of my derived class specializations and the base class specializations!.
It would seem clas template specialization is a very poor design choice
if one knows at the start that one would require specialization of the
class template. Is this a generally true conclusion - or is there some
thing I am missing?