C
Christof Warlich
Hi,
I just need a specialization for only one member function of a template
class with _many_ members. Do I really have to duplicate the source code
for all the members, i.e. for those that do not need to be specialized?
E.g. in the example below, I'd like to avoid to redefine member B::g():
#include <stdio.h>
template<int x, typename T, short y> class B {
public:
void f(void) {printf("generic f()\n");}
void g(void) {printf("generic g()\n");}
};
// specialization for T == float
template<int x, short y> class B<x, float, y> {
public:
void f(void) {printf("specialized f()\n");}
void g(void) {printf("generic g()\n");}
};
int main(void) {
B<1, int, 2> b;
b.f();
b.g();
B<1, float, 2> s;
s.f();
s.g();
}
Thanks for any suggestions,
Christof
I just need a specialization for only one member function of a template
class with _many_ members. Do I really have to duplicate the source code
for all the members, i.e. for those that do not need to be specialized?
E.g. in the example below, I'd like to avoid to redefine member B::g():
#include <stdio.h>
template<int x, typename T, short y> class B {
public:
void f(void) {printf("generic f()\n");}
void g(void) {printf("generic g()\n");}
};
// specialization for T == float
template<int x, short y> class B<x, float, y> {
public:
void f(void) {printf("specialized f()\n");}
void g(void) {printf("generic g()\n");}
};
int main(void) {
B<1, int, 2> b;
b.f();
b.g();
B<1, float, 2> s;
s.f();
s.g();
}
Thanks for any suggestions,
Christof