I've got a problem when trying to assign a function pointer to a function pointer in a struct.
I have a struct command, which holds an invocation string value, a message to acknowledge its activation, and a function to be called upon activation.
However, I am having trouble assigning the function pointer in the struct's constructor (might make the struct into a class later, not sure) below.
struct Command
{
Command(string _code, string _message, void *_func(void))
: code(_code), message(_message) { /* ERROR: */ func = _func; }
string code; // The string that invokes a console response
string message; // The response that is printed to acknowledge its activation
void *func(void); // The function that is run when the string is called
};
In the above code, marked by /* ERROR: */ I get the error, "expression must be a modifiable value". How can I fix this? I just want to pass a reference to a function to the struct.
void *func(void)is not a function pointer, it's a declaration of a function namedfuncwhich takes no arguments and return avoid*.void (*func)(void)is a variable namedfuncwhich is a pointer to a function taking no arguments and returning nothing.std::function.