I'm trying to make a simple looping menu. I moved the member function mainMenu()
above the main()
class as the internet suggested
But when I try to call mainMenu()
from inside a while
loop, the compiler gives the following error, as noted in the comments:
'mainMenu' was not declared in this scope
Below is the header file. I've been messing with types trying to get the errors to go away, I don't know if this clears up anything. If mainMenu()
isn't a member function, what is a member function?
Main.h
class main
{
private:
//variables
bool quit;
int userSelect;
//constructor
main();
//methods
mainMenu();
};
main.cpp
#include <iostream>
#include "Main.h"
using namespace std;
int main() {
bool quit = false;
int userSelect;
//mainMenu(); //** placing it here does not cause any errors **
while(!quit) {
//Main Screen
mainMenu(); // **actually I want it here, but I get the above error **
cin >> userSelect;
cin.ignore();
switch (userSelect) {
case '1':
//moveInventory
break;
case '2':
//viewInventory
break;
case '3': //user wants to exit
//exit
break;
default:
cout << "Command not recognized";
mainMenu();
break;
}
}
return 0;
} //end of main
void mainMenu() {
cout << "Welcome to the Simple Distribution Center.\n"
"1) Move Inventory\n"
"2) View Inventory\n"
"3) Save and Exit" << endl;
}