无法找到声明的函数

时间:2012-05-02 13:26:58

标签: c++

我正在尝试创建面向对象的菜单,但是我在使用int函数的返回初始化int变量时遇到了一些问题。

代码:

#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();

}

所以有:intInputHandler()和var int ret我不能做int ret = intInputHandler();

ERROR:

D:\c++\Begin\Lab6-8_UML\Debug/../Menu.cpp:121: undefined reference to `Menu::intInputHandler()'

1 个答案:

答案 0 :(得分:4)

替换

int intInputHandler()

int Menu::intInputHandler() 

您没有实现该成员,而是一个免费功能。