samedi 4 avril 2015

Generic getter with C++11

I want to try to do a generic getter by using C++11, but I have an issue if I try to define the generic getter outside the template class.


This code works fine



template <typename T>
class test
{
public:
........
//generic getter
template <typename F>
auto getter_elem_member(F fun)->decltype(fun())
{ return elem.fun(); }
private
T elem;
};


but if I try the code in this way:



template <typename T>
class test
{
public:
........
//generic getter
template <typename F>
auto getter_elem_member(F fun)->decltype(fun());
private
T elem;
};

template <typename T>
template <typename F>
auto test<T>::getter_elem_member(F fun)->decltype(fun())
{ return elem.fun(); }


I obtain the error "Member declaration not found". Where am I wrong?


Thanks in advance for any suggestions


Aucun commentaire:

Enregistrer un commentaire