Hi all :)
Currently I have a console for my program, which in short words, executes the function named what you write.
The thing is, the functions needs, for several reasons, to be members of a class.
Currently I have the code below. Manager is a class that needs to travel with the command execution.
typedef void (*Command)(std::string arg, Manager *root);
typedef std::map<std::string, Command> MapType;
MapType commands;
MapType::const_iterator commandPos;
commands.insert(std::make_pair("testcommand", testcommand));
void testcommand(std::string arg, Manager *root)
{
/* do something */
}
Then to execute depending on string I'd do this:
std::string execute = "testcommand";
std::string arguments = "helloworld";
commandPos = commands.find(execute);
(*commandPos).second(arguments, m_rootmanager); // m_rootmanager is my pointer to my Manager class
I've tried in various ways to change my code to call a static function of a class, but I get all sorts of errors.
I tried googling, but the results all seemed far away from my current code, I would like not having to do it in a whole other way than I am already.
Help appreciated :D
Happy new year, y'all :P