M
Markus
Example: A template where the instantiation, depending on the
parameterized type, needs a different implementation of one of the
methods.
template<typename T>
class MyTemplateClass
{
T var;
public:
void DoSomething();
};
The specializations of the method are something like:
template<>
void MyTemplateClass<int>:
oSomething()
{ // do something specific to a template<int> }
template<>
void MyTemplateClass<double>:
oSomething()
{ // do something specific to a template<double> }
Compare the specialized template approach to having DoSomething declared
as a virtual function in the template. I see the specialized template
approach as a way to avoid all the virtual function machinery. Is that
pretty much the gist of it?
I am noob to template specialization. It would be good to get some
general perspective on the usefulness of specialization (both kinds), so
if you have some rules of thumb as to how applicable and when applicable
specialization is, do say.
(I never got back to this, but a good topic, I think)
parameterized type, needs a different implementation of one of the
methods.
template<typename T>
class MyTemplateClass
{
T var;
public:
void DoSomething();
};
The specializations of the method are something like:
template<>
void MyTemplateClass<int>:
{ // do something specific to a template<int> }
template<>
void MyTemplateClass<double>:
{ // do something specific to a template<double> }
Compare the specialized template approach to having DoSomething declared
as a virtual function in the template. I see the specialized template
approach as a way to avoid all the virtual function machinery. Is that
pretty much the gist of it?
I am noob to template specialization. It would be good to get some
general perspective on the usefulness of specialization (both kinds), so
if you have some rules of thumb as to how applicable and when applicable
specialization is, do say.
(I never got back to this, but a good topic, I think)