#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <vector>
using std::vector;
usingnamespace std;
#include "Menu.h"
Menu::Menu()
: count(0)
{
}
void Menu::addMenu(string descript, void(*f) (void))
{
if (count < mi.size())
{
mi[count].func = f;
mi[count].descript = descript;
count++;
}
}
void Menu::runMenu()
{
for (;;)
{
system("CLS");
for (int i = 0; i < count; i++)
{
cout << mi.push_back(i) << endl;
}
runSelection();
}
}
void Menu::runSelection()
{
int select;
cin >> select;
if (select <= count)
this->mi[select - 1].func();
}
void Menu::waitKey()
{
cout << "Press any key to continue" << endl;
while (!_kbhit());
fflush(stdin);
}
Line 35 of the CPP file is giving me an error, and overall I'm not certain the runMenu function is correct either, even though it doesn't give an error.
It looks like line 35 should be: cout << mi[i] << '\n'; You're trying to print out the contents of the vector, not add elements to it. std::vector has this method called size which you should probably use (there is no reason to keep your count member.)
Thanks Cire!
However on this line cout << mi[i] << '\n'
I get this error.
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'menuItem' (or there is no acceptable conversion)