I'm sorry if this is a very noobish question, but I'm confused on how you can specify std::function argument lists like this:
std::function<void(double)> func;
But in an actual function, this doesn't work:
void passFunc(void(double) func) {}
For the method above you have to specify a function pointer. So how is void(double) allowed to be passed into std::function? Is void(double) even a type? If not, how can it be in the argument list for std::function? If it is a type, why is it not valid to have void(double) be the type of a function parameter?
CodePudding user response:
You can declare a type like that:
using Func = void(double);
But in the definition, you still need the name of the argument; otherwise, you could not use it in the function:
void passFunc(void func(double)) {}
Note that func
is inbetween the return type and the arguments. If you don't like that, you can use the above-defined type:
void passFunc(Func func) {}