gpt4 book ai didi

c++ - 下标运算符重载错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:25 25 4
gpt4 key购买 nike

这是我的双向链表类中的一个函数,但每次编译时,我都会收到此消息:“从类型为“int”的临时类型中对类型为“int&”的非常量引用的初始化无效。我只能了解其他方法。

int& LinkedList::operator[](int index)
{
Node* current = head_;

for(int i = 0; i < index; i++){
current = current->getNextNode();
}

return(current->getValue()); // getValue() returns an int
}

提前致谢!

最佳答案

简单的回答:getValue 也必须返回一个 int&

关于c++ - 下标运算符重载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9594140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com