Comments in red:
Code:
class Menu {
private:
virtual void MenuFunc() = 0;
virtual void AddItem(const std::string& s, char c, Func f);
};
class ViewContractMenu : virtual public Menu {
Don't use virtual here -- No need. [Same for all other similar ones]
public :
void MenuFunc()
{
Clrscr();
cout << "\t\t\t\tÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n";
cout << "\t\t\t\tº CONTRACT DETAILS º\n";
cout << "\t\t\t\tÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n";
rental.ViewContract();
Pause();
}
};
<...snip...>
class ContractMenu : public ViewContractMenu,
public AddContractMenu,
public DeleteContractMenu,
public EditContractMenu
Why are you inheriting here - I don't think that's the right thing
{
public:
typedef static void (*Func)();
private:
struct Item
{
std::string descr;
char choice;
Func func;
};
typedef std::vector<Item> ItemVector;
ItemVector mainMenu, fleetMenu;
public:
void addItem(const std::string& s, char c)
{
Item item;
item.descr = s;
item.choice = c;
item.func = MenuItem(); /* NB: This is where the big issue is *** */
Which menuitem is this? There are four in your iheritance, and they are not the same.
if(!isFleetMenu()) {
This is probably not the right way to achieve this - perhaps having two instances of this object, each with its own list would be the right solution. [1]
mainMenu.push_back(item);
}
else
fleetMenu.push_back(item);
}
};
Are you basing this on the menu system that I posted a long time ago?
If you have "menu objects", then you should probably not use a function pointer, but rather use them as functors - store a pointer to "Menu", rather than a function pointer. When the menu is selected, call the Menu->MenuFunc(). Since it's a virtual function, it will call the right thing.
--
Mats