If you really want to use template in order to accept any kind of function's signature, then the implementation should be something similar to this:
class A { public: template<typename F, typename... Args> auto f(F&& funct, Args&&... args) { return funct(std::forward<Args...>(args)...); } };
That because you've said in the comment:
Q: Does the type F is needed in the class of only for method f?
A: only the method.
Because of that, it should be useless to have a template class, when you can just have a template method.
An here, an example how to call the method which just invoke the "callable object with its parameters", in this case a lambda function:
int main(int argc, char* argv[]) { A a; a.f([](int i) -> int { return i + 5; }, 12); // |------callable object-----------| |argument of function| return 0; }
Practically, the method f accepts as first argument a "callable object" and as further arguments any parameters requested in order to invoke the first argument.
Additional Notes:
If you want to pass to method f a certain type of signature of function, for example: int (*)(int), then you can avoid using template and pass an object of type std::function.
This is just an example:
#include <functional> class A { public: // method g accept a function which get a integer and return an integer as well. int g(std::function<int(int)> funct, int arg) { return funct(arg); } };
Fis needed in the class of only for methodf?class F), what is the meaning ofF(i)then?