R
Ruben Campos
I have a template class, and I want to create partially (totally)
specialized versions of it, by adding new methods to the original base
template specification. But it seems that partially (totally) specialized
templates are completely independent from their base templates, so in order
to do what I want, I have to redeclare and redefine (in both cases
duplicating code) all methods and attributes of the base template in each of
the partially (totally) specialized ones.
In the example below:
template <tyename T, int N>
class MyTemplate
{
public:
void f () { /* ... */ }
};
template <typename T>
class MyTemplate <T, 1>
{
public:
void g () { /* ... */ }
};
Is there any way to include f() in the interface of MyTemplate <T, 1>, other
than redeclaring and providing a copy of MyTemplate <T, N>::f()'s
implementation? I've tried to redeclare f() inside MyTemplate <T, 1>, and
provide only one implementation (the base template one's), but it doesn't
works. Thank you very much in advance.
specialized versions of it, by adding new methods to the original base
template specification. But it seems that partially (totally) specialized
templates are completely independent from their base templates, so in order
to do what I want, I have to redeclare and redefine (in both cases
duplicating code) all methods and attributes of the base template in each of
the partially (totally) specialized ones.
In the example below:
template <tyename T, int N>
class MyTemplate
{
public:
void f () { /* ... */ }
};
template <typename T>
class MyTemplate <T, 1>
{
public:
void g () { /* ... */ }
};
Is there any way to include f() in the interface of MyTemplate <T, 1>, other
than redeclaring and providing a copy of MyTemplate <T, N>::f()'s
implementation? I've tried to redeclare f() inside MyTemplate <T, 1>, and
provide only one implementation (the base template one's), but it doesn't
works. Thank you very much in advance.