If you have a real working application and you see that everything you are asking works fine, so where is the problem to solve? :)
I didn't understand this paragraph:
lastly when i 'delete this' from MainMenu or AboutMenu, the rest of the code in the function is still executed. i'd assume if the object no longer existed, there would be nothing to execute?
If I do understand, put "delete this" as the last line in the function. The function "exists" seperately from the class variables and you don't delete the function when you delete the class object.
Previous two paragraphs will work as you described - delete will delete the correct object if your didn't forget to make the destructor virtual.
Scott Meyers likes these theretical questions: http://www.aristeia.com/pu
@itsmeandnobodyelse: C++ without pointer? :) Please do not discuss it here. It just sounds funny for me.





by: itsmeandnobodyelsePosted on 2009-08-29 at 05:42:01ID: 25213847
In C++ you rarely need pointers. You better try with out pointers first:
// forward declarations
class Menu;
class AboutMenu;
class MainMenu;
class Game
{
...
public:
void showAboutMenu();
};
enum MenuItemMethod { MIM_HELP, MIM_NEW, MIM_STORE, ... };
class MenuItem
{
std::string text;
int shortcut_pos;
bool check;
int method;
public:
MenuItem(const char* pszText, int shortcut, bool chk, MenuItemMethod mim)
: text(pszText), shortcut_pos(shortcut), check(chk), method(mim) {}
};
class Menu
{
std::vector<MenuItem> items;
public:
void show();
void addItem(const MenuItem& mi);
};
class MainMenu : public Menu
{
};
class AboutMenu : public Menu
{
};
void Game::showAboutMenu()
{
AboutMenu menu;
menu.addItem("Help", 0, false, MIM_HELP);
menu.addItem(...);
...
menu.show();
};