You can not. Perfect forwarding only works by combining templates and rvalue links, because it depends on what type of real type T&&is evaluated when T is specialized. You cannot mix templates and virtual functions.
However, you can solve your problem with a kind of type-erasing mechanism:
struct base {
virtual void invoke() = 0;
};
template <class T>
struct derived : public base {
derived( T&& yourval ) : m_value(std::forward(yourval)) {}
virtual void invoke() { }
T&& m_value;
};
ltjax source
share