vendredi 27 mai 2016

Passing universal pointer class to functions

I am trying to implement a universal pointer class, which holds eighter a raw pointer or a shared_ptr. I have an enum to indicate what the pointer object holds.

enum class memory_management_t{
    raw_pointer,
    counted_pointer,
};

the pointer class is a template class:

template<class T, memory_management_t MEM>
class pointer;

which overloads the -> and * -operators. Now my question is if a virtual member function of a class wants to use the pointer class like this:

void func(pointer<std::string> s);

Since func could be virtual, this would not be possible:

template<memory_management_t MEM>
void func(pointer<std::string, MEM> s);

It would be nice if I could pass pointers to functions without overloading those functions, no mather if they are pointer<T, memory_management_t::raw_pointer> or pointer<T,memory_management_t::counted_pointer>

How can I achieve this efficient?

Aucun commentaire:

Enregistrer un commentaire