C ++中

时间:2016-04-10 19:55:10

标签: c++

我仍在尝试处理C ++编程,我正在尝试编译一个代码,用于创建不同的人员对象并将书名保存到使用树的人员。我一直在说:

  

对'insert_Book()'

的未识别引用      

对'search_Book()'

的未识别引用

在我的insert()函数中。为什么是这样?谢谢!

//insert function
void insert(){
    char ch;

    cout << endl << "@Insertion module...............";
    do {
     sub_menu();
     cin >> ch;
     ch = tolower(ch);

     switch(ch) {
        case 'p':   if(insert_personnel() != 0)
                        cout << "@INSERTION OPERATION FAILED." << endl;
                    else
                        cout << "@INSERTED SUCCESSFULLY." << endl;
                        break;
        case 'e':   if(insert_employee() != 0)
                        cout << "@INSERTION OPERATION FAILED." << endl;
                    else
                        cout << "@INSERTED SUCCESSFULLY." << endl;
                        break;
        case 'f':   if(insert_faculty() != 0)
                        cout << "@INSERTION OPERATION FAILED." << endl;
                    else
                        cout << "@INSERTED SUCCESSFULLY." << endl;
                        break;
         case 's': if(insert_student() !=0)
                        cout << "@INSERTION OPERATION FAILED." << endl;
                    else
                        cout <<"@INSERTED SUCCESSFULLY." << endl;
                        break;
         case 'b': if(insert_Book() !=0)
                 cout << "@INSERTION OPERATION FAILED." << endl;
             else
                 cout <<"@INSERTED SUCCESSFULLY." << endl;
                        break;
         case 'g': if (search_Book() !=0)
                 cout << "@INSERTION OPERATION FAILED." << endl;
             else
                 cout <<"@INSERTED SUCCESSFULLY." << endl;
                    break;
        case 'q':   cout << endl << "@Exiting the insertion..." << endl;
                    cin.get();
                    break;
        default:        cout << endl << "@ERROR - Invalid input." << endl;
                    cout << "@Try again....." << endl;
       }
    }
    while (ch != 'q');
}

int search_Book(Book *root,char *ntitle){
    if (root == NULL){
        cout<<"No Books found";
        return -1;
    }
    else if(ntitle == root->title){
        cout<<"Title:\t"<<root->title<<endl<<"URL:\t"<<root->url<<endl;
        return 0;
    }
    else if(ntitle[0] < root->title[0]){
        return search_Book(root->left,ntitle);
    }
    else {
        return search_Book(root->right,ntitle);
    }
}
int insert_Book(){
    char name[50];
    char title[100];
    char url[100];
    Student* node;
    cout<<"Enter the name of the student you want the book to be added to: ";
    cin>>name;
    node = searchstudent(name);
    if(node == NULL){
        return 1;
    }
    else{
        cout<<"Enter the Title: ";
        cin>>title;
        cout<<"Enter the url: ";
        cin>>url;
        add_Book(node->bookTree,title,url);
        return 0;
    }

}

1 个答案:

答案 0 :(得分:3)

insert()在定义之前使用insert_Book()search_Book()(在insert()之后定义它们)。

两种解决方案:

1-在insert_Book()

之前移动search_Book()insert()代码

2-或者在insert()之前声明它们:只需写

int insert_Book();
int search_Book(Book *root,char *ntitle);

这告诉编译器不要担心,这些将很快实现...您可以在insert()之后实现它们。