C++ 中 header 的问题

An issue with a header in C++

我运行用header成问题了。我有一个数据结构分配 (LinkedList),并且 header 已经在分配中给出。我做了所有其他代码,但是当我 运行 程序时,错误出现在 header!这是错误:

(错误指向"private")

typedef int 元素类型;

struct node {

    ElementType data;
    node * next;
};

class List {

public:
    List();                          //Create an empty list.
    bool Empty();                    //Return true if the list is empty, otherwise return false.
    void InsertAtEnd(ElementType x); //Insert a value x on the end of the list.
    void Delete(ElementType x);      //If value x is in the list, remove x.
    void Display();                  //Display the data values in the list in the order inserted.
    int Smallest();                  //Find and return the smallest value in the list.
    int Largest();                   //Find and return the largest value in the list.
    int Range()                      //Computer and return the range of the values in the list.

private:

    node * first;                    //Pointer to first node.
};

int Range() 后面没有 ;

正是如此。

在“private”之前缺少一个“;”。

private: 之前的最后一段代码应该是 ;,但不是。

int Range() 
//         ^

添加它。

int Range()”这一行应该是“int Range();”。换句话说,您在该行中缺少分号,在编译器看来,分号紧接在 "private:" 关键字之前。

上面的代码示例中存在语法错误。分号;缺少

    int Range()

应该是

    int Range();

private:
...