c++ - 将节点指针设置为空

标签 c++ linked-list nodes

首先。感谢大家的帮助!

这就是问题所在。尝试将列表的边之一设置为空

list[i].getAttachedNode(j) = 0;

这是错误。

Prj3.cpp:165:34: error: lvalue required as left operand of assignment

这是我的列表声明。

Node list[47];

这是附加节点的实现。

Node* Node::getAttachedNode(int direction) {return attachedNode[direction];}

[b]这是它所在的 block 。

for(int i = 0; i<48; i++)
      {
        for(int j = 0; j<6; j++)
        {  
        string info = g.returnInfo(i,j);

            switch(j)
                {
            case 0:
            list[i].setNodeName(info);
            break;
            case 1:
            if(info.compare(null) == 0)
            {list[i].getAttachedNode(j) = 0;}
            break;
                }
        }
    }

最佳答案

错误很明显:

list[i].getAttachedNode(j) 

是一个 r 值,因此不能分配给它。只需让 getAttachedNode 返回一个引用:

Node*& Node::getAttachedNode(int direction) {return attachedNode[direction];}

关于c++ - 将节点指针设置为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13316891/

相关文章:

javascript - 节点等待不等待 promise

orientation - Graphviz:控制节点在子图中对齐

c++ - Glew 不初始化

c++ - 打印 unordered_set 的元素

c - 销毁C中的链表

java - 不使用 previous 的 ListIterator 解决方案

c++ - 如何根据参数在复制构造函数和默认构造函数之间切换?

c++ - 如何将包含不同语言的 wstring 行写入文件?

Python : why doesn't a. pop() 修改链表(自定义链表类)

c++ - 遍历链表和修改或插入节点C++