簡體   English   中英

返回值類型與函數類型CONST不匹配

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM