I suspect you want something like this:
template <typename F> class Class; template<typename R, typename... P> class Class<R(P...)> { public: std::function<R(P...)> func; void callFunc(P... p) { func(p...); } };
Using partial specialization, you can easily determine the type you want.
As an example, you can use it like:
Class<int(double)> c;
Of course, I noticed that you do not have constructors for your class, so calling func is not a good idea, but it is pretty easy to define it and pass the correct function as an argument.
The following is a working and working example in which I used operator() to call a function:
#include <functional> template <typename F> class Class; template<typename R, typename... P> class Class<R(P...)> { public: Class(std::function<R(P...)> f): func{f} { } void operator()(P... p) { func(p...); } private: std::function<R(P...)> func; }; void fn() { } int main() { std::function<void()> f = fn; Class<void()> c{f}; c(); }
source share