我正在做一个只移动的等价物std::function
。move_function
包含指向基类的指针,move_function_base
该类型会擦除底层仿函数类型。move_function_imp
继承move_function_base
并持有类型化的底层仿函数。move_function_imp
定义如下:
template<class F, class ReturnType, class... ParamTypes>
class move_function_imp : public move_function_base<ReturnType, ParamTypes...> {
typename std::remove_reference<F>::type f_;
public:
virtual ReturnType callFunc(ParamTypes&&... p) override {
return f_(std::forward<ParamTypes>(p)...);
}
explicit move_function_imp(const F& f) : f_(f) {}
explicit move_function_imp(F&& f) : f_(std::move(f)) {}
move_function_imp() = delete;
move_function_imp(const move_function_imp&) = delete;
move_function_imp& operator=(const move_function_imp&) = delete;
};
当我使用它时,我得到一个错误,即构造函数不能互相重载。我究竟做错了什么?完整代码位于此处。
编辑:从ideone链接粘贴的错误:
prog.cpp: In instantiation of ‘class move_function_imp<main()::__lambda0&, void>’:
prog.cpp:39:30: required from ‘move_function<ReturnType(ParamTypes ...)>::move_function(F&&) [with F = main()::__lambda0&; ReturnType = void; ParamTypes = {}]’
prog.cpp:62:38: required from here
prog.cpp:20:12: error: ‘move_function_imp<F, ReturnType, ParamTypes>::move_function_imp(F&&) [with F = main()::__lambda0&; ReturnType = void; ParamTypes = {}]’ cannot be overloaded
explicit move_function_imp(F&& f) : f_(std::move(f)) {}
^
prog.cpp:19:12: error: with ‘move_function_imp<F, ReturnType, ParamTypes>::move_function_imp(const F&) [with F = main()::__lambda0&; ReturnType = void; ParamTypes = {}]’
explicit move_function_imp(const F& f) : f_(f) {}
^
prog.cpp:19:12: error: ‘move_function_imp<F, ReturnType, ParamTypes>::move_function_imp(const F&) [with F = main()::__lambda0&; ReturnType = void; ParamTypes = {}]’, declared using local type ‘main()::__lambda0’, is used but never defined [-fpermissive]