[英]Return value type does not match the function type CONST
當我在另一個函數上使可變長度const時,不確定為什么在此函數上發生錯誤
int list::length() const {
return length;
}
上方的CPP文件
頭文件如下
class list {
private:
struct Node
{
int info;
Node *next;
};
int length;
Node *head;
public:
list();
list(const list& otherlist);
~list();
int list::length() const;
};
第一個問題是您要在班級內部限定length()
。 刪除list::
。 第二個問題是您的成員變量length
和成員函數length
沖突,因為它們具有相同的名稱。
我將重命名您的成員,以免他們與功能沖突。 考慮length_
和head_
。
編輯:請在將來也發布編譯器錯誤,因為這會使其他讀者的工作更容易:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.