Let’s assume mf_ptr is a typedef of member function pointer of a class. And we have the flowing code:
map<string, mb_ptr> cmd_table;
cmd_table["exit"] = &class_name::exit;
string cmd;
while (cin >> cmd){
(this->*cmd_table[cmd])();
}
So how should i define the function exit() to exit the while loop?
You have a few options:
Raise an exception in the exit function, and catch it in the while loop.
Have all your functions return a boolean, whether or not to exit the while loop.