C++ 我收到一个错误,说“范围内未贴花”

C++ 我收到一个错误,说“范围内未贴花”,c++,scope,linked-list,C++,Scope,Linked List,这是一个链表程序作业,我相信我几乎完成了该程序。在main方法中,我在这些行中不断遇到4个错误。我想知道是否有人能告诉我示波器出了什么问题。塔克斯 错误:“addFirst”未在此作用域中声明 addFirstbooklist 错误:“addLast”未在此作用域中声明 addLastbooklist 错误:“isInTheList”未在此作用域中声明 isInTheListbooklist 错误:“deleteBook”未在此范围内声明 删除书目 然后我的头文件被保存为Program.h在同一

这是一个链表程序作业,我相信我几乎完成了该程序。在main方法中,我在这些行中不断遇到4个错误。我想知道是否有人能告诉我示波器出了什么问题。塔克斯

错误:“addFirst”未在此作用域中声明 addFirstbooklist

错误:“addLast”未在此作用域中声明 addLastbooklist

错误:“isInTheList”未在此作用域中声明 isInTheListbooklist

错误:“deleteBook”未在此范围内声明 删除书目

然后我的头文件被保存为Program.h在同一个文件夹中,代码如下

#ifndef PGM_03_H//<-
#define PGM_03_H//<- both these need to have the same name

#include <string>


using namespace std;

/*class definition for BookNode
 * which is non-compatible. i.e it has a pointer to the next BookNode
 */


class BookNode{

    private : 
        std::string bookTitle;
        BookNode * next;
    public : 
        //default constructor
        BookNode(){bookTitle = "";next = NULL;} 

        //custom constructor
        //it initializes book with title        
        BookNode(string title){
            bookTitle = title;
            next = NULL;

        }

        //getter functions
        std::string getTitle(){
            return bookTitle;

        }

        BookNode * getNext(){
            return next;

        }

        //setter functions
        void setTitle(std::string newTitle){
            bookTitle = newTitle;

        }

        void setNext(BookNode * newNext){
            next = newNext;

        }

};


/*
* class definition for BookList
* which is a linked list that uses object of BookNode as node.
* it has only one variable: head, which is a BookNode pointer.
*/

class BookList{

    private:
        BookNode * head;



    public:
        //default constructor
        BookList(){
            head = NULL;

        }


        //destructor, which will be called automatically
        //it deletes all nodes in the linkedlist
        ~BookList();

        //add new node as the first node in the booklist
        void addFirst(BookNode *);


        //add new node as the last node in the booklist
        void addLast(BookNode *);


        //traverse function. It will print out info on BookNode
        void traverse();


        //check if the given book is in the list
        bool isInTheList(std::string);

        //delete the given book
        //return true if it was deleted
        //return false if it was not found
        bool deleteBook(std::string);



};





#endif
addFirst等是BookList类的成员,但您调用它们的方式就像调用函数一样。您需要BookList类的一个实例来处理这些方法

您还将一个BookList传递给addFirst,它需要一个BookNode。您希望它看起来像:

booklist.addfirst(node);

它应该被声明为没有贴花…你可以用你的问题来修正打字错误。这也将是一个很好的机会,用一个。
booklist.addfirst(node);