lundi 26 novembre 2018

Writing methods in the implementation file with templates

I'm trying to write a class which can have about 50+ methods. The class is templated like this:

template <typename T>
class xyz<T>
{
private:
    void method1(int x, int at);
public:
    xyz();
    ~xyz();
    void method2(T a);
    void method3(T a);
    void metho(T a);
    .. //Other methods
};

Now I would like to implement these methods in a separate implementation .cpp file, so i would have to do something like this:

#include "xyz.h"
template <typename T>
xyz<T>::xyz()
{
}

template <typename T>
xyz<T>::~xyz()
{
}
template <typename T>
void method1(T a){
..
}
template <typename T>
void method2(T a){
..
}

So as you can see, I have to make a template each time I implement a new method. Do I have any better way of doing this than making the template 50+ times? So that I'd only make it once and can reuse it every time? Sorry if this is too obvious (I believe it is).

Aucun commentaire:

Enregistrer un commentaire