mercredi 29 septembre 2021

c++11 how to convert legacy class to template

I have a legacy class like:

class Wrapper{
public:
    Wrapper(void*);
    void* get();
};

I want to create a type safe wrapper like:

template<class T>
class Wrapper{
public:
    Wrapper(T);
    T get();
};

Stuff like this won't work because of C++11:

template<class T = void*> //Here I would need <>
class Wrapper...

typedef Wrapper<void*> Wrapper; //This isn't allowed

Is there a way to convert Wrapper to a template class without editing all places where it's already used?

Aucun commentaire:

Enregistrer un commentaire