I'm way over my head here.... But trying to piece this together mostly to see if it's even possible, and to help myself learn about function pointers and templates. I just about understand the examples I've got working but I'm over-reaching for sure.
For no reason other than my own amusement and learning I'm trying to combine the two.
So I can essentially have a function pointer to any function, no matter what or how many arguments are required.
The goal is to have the function pointer point to any function, no matter what or how many arguments are required. Is the template not even needed for this?
I did see that, yes! Although it's just as much over my head. Maybe the answer is in there but I do not see it yet. (Plenty of studying left to do)
Haven't decided yet. Just exploring to see what's possible. The thought process started because I gave my button class function pointers to call when pressed. Which is fine for void functions with no parameters but I thought 'what if I wanted to hook in other functions that looked a little or very different'. Sure you could probably write a million overloads. But maybe templates are the answer. Who knows!
you can define function ptrs to functions with a specified set of arguments. it's common to specify a void* argument which can then be cast to the type needed by the function
Those are nicknamed, "callback" functions. As they don't expect to return any values, they also don't accept any parameters. That makes them a lot safer than calling void function pointers from a main program, and/or passing parameters with them. They're normally just event handlers.