Reputation: 683
i am trying to make a object oriented menu, but i encountered some problems with initialising an int variable with the return of a int function.
Code:
#include <Menu.h>
#include <iostream>
using namespace std;
void Menu::showMainMenu(){
cout<<"""Main Menu"""<<endl;
cout<<"1. Manage students"<<endl;
cout<<"2. Manage assignments"<<endl;
cout<<"3. Manage statistics"<<endl;
cout<<"4. Print database"<<endl;
cout<<"0. Exit"<<endl<<endl;
}
void Menu::showStudentMenu(){
cout<<"""Student Menu"""<<endl;
cout<<"1. Add student"<<endl;
cout<<"2. Remove student"<<endl;
cout<<"3. Edit student"<<endl;
cout<<"4. Print student"<<endl;
cout<<"5. Print students"<<endl<<endl;
}
void Menu::showAssignmentMenu(){
cout<<"""Assignment Menu"""<<endl;
cout<<"1. Add assignment"<<endl;
cout<<"2. Remove assignment"<<endl;
cout<<"3. Edit assignment"<<endl;
cout<<"4. Print assignment"<<endl;
cout<<"5. Print assignments"<<endl<<endl;
}
void Menu::showStatisticsMenu(){
cout<<"""Assignment Menu"""<<endl;
cout<<"1. Add assignment"<<endl;
cout<<"2. Remove assignment"<<endl;
cout<<"3. Edit assignment"<<endl;
cout<<"4. Print assignment"<<endl;
cout<<"5. Print assignments"<<endl<<endl;
}
string Menu::stringInputHandler(){
string input;
cout<<"enter:"; cin>>input; cout<<endl;
if(!input.empty()){
return input;
}
cout<<"Input cannot be empty"<<endl;
stringInputHandler();
return "Error! (f:sIH)";
}
int intInputHandler(){
int input;
cout<<"enter:"; cin>>input; cout<<endl;
if(input){
return input;
}
cout<<"Input cannot be empty"<<endl;
intInputHandler();
return 0;
}
void Menu::CommandControllMain(){
showMainMenu();
int ret;
ret = intInputHandler();
while(ret){
switch(ret){
case 1:CommandControllStudent();break;
case 2:CommandControllAssignment();break;
case 3:break;
case 4:break;
case 0:break;
default:cout<<"Wrong option selected!";break;
}
}
}
void Menu::CommandControllStudent(){
showStudentMenu();
int ret = intInputHandler();
}
void Menu::CommandControllAssignment(){
showAssignmentMenu();
int ret =intInputHandler();
}
void Menu::CommandControllStatistics(){
showStatisticsMenu();
int ret =intInputHandler();
}
so there is: intInputHandler()
and a var int ret
and i cant do int ret = intInputHandler();
ERROR:
D:\c++\Begin\Lab6-8_UML\Debug/../Menu.cpp:121: undefined reference to `Menu::intInputHandler()'
Upvotes: 0
Views: 86
Reputation: 258618
Replace
int intInputHandler()
with
int Menu::intInputHandler()
You're not implementing the member, but a free function.
Upvotes: 4