Quote:
As an alternative, you could try implementing the menu via callback functions. You could create a menu item class that stores the description of the menu item and a function pointer to the function that you want to call if the user selects that option. A menu class could then store a list of menu items and perhaps a heading for the menu. The menu class could have a member function that displays the menu (in a loop, automatically numbering the menu items), handles user input, and then runs the callback function of the selected menu item.
Once you have written these two classes, creating a menu would just involve creating a menu object and adding menu item objects to it. The tradeoff is that this is more initial work in implementing these two classes and you have to create a callback function for each menu option (but for a reasonably complex option, you would write a function for that anyway). On the other hand, you can just create menu objects in those functions so as to have sub-menus.
This sounds very interesting. Although I am not used of pointers (it's the next chapter on my C++ book) I would like to see a source code that does this implementation. Could you or anyone else post it here ?