I\'m having an issue with a C++ assignment, we had to create a menu using an arr
ID: 3758583 • Letter: I
Question
I'm having an issue with a C++ assignment, we had to create a menu using an array, and then change the array to a vector, and I for the life of me, can't figure out why I'm running into a few errors.
ORIGINAL CODE:
void Menu::addMenu(string descript, void(*f) (void))
{
if (count < MAXCOUNT)
{
mi[count].func = f;
mi[count].descript = descript;
count++;
}
}
void Menu::runMenu()
{
for (;;)
{
system("CLS");
for (int i = 0; i < count; i++)
{
cout << mi[i].descript << endl;
}
runSelection();
}
}
NEW CODE:
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() << endl;
}
runSelection();
}
}
I have the vector declared as follows inside of a class
vector<menuItem> mi;
The vector uses a type made by a struct.
struct menuItem
{
void(*func) ();
string descript;
};
And I keep getting this error
error C2661: 'std::vector<menuItem,std::allocator<_Ty>>::push_back' : no overloaded function takes 0 arguments
1> with
1> [
1> _Ty=menuItem
1> ]
Explanation / Answer
That is because you need to include "#include<vector>" in your program.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.