Answer the question
In order to leave comments, you need to log in
Is using static justified in my case?
I have some class. In this class, I have the functionality of processing user commands. Let 's say our "bash" ..
And now I have a question. In the class I have a private std::map, this map consists of a pair of .
There is also a CommandListener method that accepts a string from the user. Further, this method searches for a key match with the user's string and, if found, executes the value, that is, the method.
Example code:
map
std::map<std::string, void(*)()> Functions = {
{"SomeF1", SomeF1},
{"SomeF2", SomeF2},
{"SomeF3", SomeF3},
{"SomeF4", SomeF4},
// ...
};
void Client::CommandListener(std::string Command)
{
std::map<std::string, void(*)()>::iterator it = Functions.find(Command);
if (it == Functions.end()) std::cout << "This command does not exist\n";
else it->second();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question