I am searching for a solution to my problem.
I have a situation where I create a library. My library lets users add commands and store them. Each command should have a function pointer which can be set to a user created callback function.
What I want is a scenario where the callback functions can be any type. What I mean by any type is any kind of return type with any types of arguments.
My datastruct would look something like this:
struct Command{
uint64_t alias;
anytype/amount args...;
anytype (*f_ptr);
};
Then my library would go over an array of commands and call the correct command with its corresponding callback.
I found a solution here, but the functions used are not supported on C++11. How should I approach this problem?
Further information
It might be good to have some background information.
The library is built on top of MQTT. I want the user to be able to specify commands it can receive from MQTT. I want to give the user full functionality by letting them think of their own commands.
If a message comes in through MQTT and it corresponds with the self-created command I want to execute their assigned callback function to let them handle their own commands.
Again, since I want to give as much functionality as possible I want to allow any type of callback function. This is when I came up with the command struct solution.