gpt4 book ai didi

c++ - 左值需要作为 C++ 中的一元 '&' 操作数错误

转载 作者:行者123 更新时间:2023-11-27 23:10:02 25 4
gpt4 key购买 nike

我试图通过引用将一个值传递给另一个指针,但是我收到错误:需要左值作为一元“&”操作数。

以下是我的尝试:

Node<Item,Key> *root;

Node<Item, Key> *x= root;

x= &x->getLeft(); // it does not let me use &

以下是我的 getLeft() getter:

template<typename Item, typename Key>
Node<Item, Key>* Node<Item, Key>::getLeft() {

return left;
}

如果有人能指出我的错误,我将不胜感激。提前致谢。

最佳答案

你的意思是:

x = x->getLeft();

getLeft() 的返回值已经是一个指针。

关于c++ - 左值需要作为 C++ 中的一元 '&' 操作数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20906894/

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