I don't understand why your design is so complicated.
Why would a "full menu" contain "options" that are
not "menu options"? Aren't they menu options by virtue of the fact that they
are in a menu? Even then, why would you need to downcast? Is there something that menu options can do that ordinary options can't? If so, why?
Also, why do you have to ask the menu what its "selected index" is, and then ask it
again what option corresponds to that index? Why would calling code ever even care that the menu has such a concept as an "index"? Your interface is too complicated; what the calling code wants to know is
what option is selected, so that's what the member function should be: getSelectedOption().
Also, why do you have to save the old menu and create a new one in two steps? The "menu stack" can be more intelligent than that. Why would you ever push something and then
not create a new menu? Why would you ever create a new menu
without remembering the current one? Pairs of actions are
algorithms; encapsulate them.
Also, don't convert characters to integers just to figure out what character they are. There are symbolic constants for characters: you just put them in single quotes.
Also, use references to avoid repeating common sub-expressions (often, this is a temporary measure until you can refactor in a better way).
Quote:Original post by Palidorflame
I apologize if something i comment on about programming is either incorrect, or not efficient. I just started c++ for the first time in November. In my opinion, i'm doing a fairly good job, but I had a small coding problem that i was hoping someone here could help me discover (that's the point of forums, right?).
I won't try to speak for other forums, but the point of
our forum is to
teach you something. If you are not interested in learning from us, then I suppose I won't very easily convince you otherwise, but I would urge you to reconsider. You don't need to apologize for not knowing something, but you are expected not to
assert things without being able to
justify them. (Whether or not you are doing a "fairly good job" is (a) dependant on a lot of missing context (previous programming experience?) and (b) largely irrelevant anyway.)
Antheus knows what he's talking about, here. Also, consider that
constant overheads are
more acceptable in a large project: they get averaged out. Basically the only people who care about <iostream> adding half a meg to the final executable size are the ones who have a ridiculously small executable size as a design requirement (i.e., people in the demo scene).