【问题标题】:Return value type does not match the function type CONST返回值类型与函数类型 CONST 不匹配
【发布时间】:2016-04-04 00:58:12
【问题描述】:

当我在不同的函数上设置可变长度 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;

};

【问题讨论】:

    标签: c++ class linked-list constants


    【解决方案1】:

    第一个问题是你在你的班级里有资格length()。删除list::。第二个问题是您的成员变量length 和您的成员函数length 冲突,因为它们具有相同的名称。

    我会重命名您的成员,以免它们与功能冲突。考虑length_head_

    编辑:将来也请发布编译器错误,因为它使其他读者的工作更容易:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 2016-10-29
      相关资源
      最近更新 更多