I'm trying to store a list of user commands in a struct. The struct consists of a command (char array) and a pointer to a static member function which may have any number of arguments. I would like to be able to instantiate the struct, and store them in a vector, and then when accessing one, to call the function pointer it stores, passing in the necessary arguments.
After a lot of reading and experimenting this is what I've come up with:
template<typename F, F func, typename... Args>
struct InputCommand
{
public:
char input[ 32 ];
void ( Interpreter::*func )( Args... args );
InputCommand( const char input[] )
{
strcpy( this->input, input );
}
};
The above seems reasonably logical to me, however I get an error when trying to declare my vector of type InputCommand:
vector<InputCommand> m_commandList;
InputCommand<void *, cmdAddState, const char, const char> command( "addstate" );
m_commandList.push_back( command );
According to the compiler the declaration needs a command list but I'm really not sure what to do. FYI the function cmdAddState is as follows:
static void Interpreter::cmdAddState( const char, const char );
Any help would be very much appreciated. Thank you!