mardi 20 février 2018

error when moving derived class unique_ptr to its base class

I have an interface class as below:

struct option_base 
{
virtual ~option_base() = default;
virtual int get_value() const noexcept= 0;
};

this class is implemented as below:

template <int T>
struct option : public option_base
{
int get_value() const noexcept override {return T;}
};

I created an option_style.hpp class as below to call an option with a keyword.

#ifdef SYS_OPTION_STYLE

OptionStyle(one, decltype( std::declval< option<1> >() ))
OptionStyle(two, decltype( std::declval< option<2> >() ))
OptionStyle(three, decltype( std::declval< option<3> >() ))
OptionStyle(four, decltype( std::declval< option<4> >() ))
....

#endif

in my factory class that return an option_base given a keyword, I do the follwoing

#define SYS_OPTION_STYLE
#define OptionStyle(tag, class_t)                                            \
    if (keyword.compare(#tag) == 0)                                          \
    {                                                                        \
        std::unique_ptr<option> opt{std::move(std::make_unique<class_t>())}; \
        return opt;                                                          \
    }
#include <networker/socket/options/option_styles.hpp>
#undef OptionStyle
#undef SYS_OPTION_STYLE

I get compilation error of

no matching function for call to ‘std::unique_ptr<option<1>&&,
std::default_delete<option<1>&&> >::unique_ptr(option<1>*) return
unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));

what am I missing in my implementation ??!!!

Aucun commentaire:

Enregistrer un commentaire