gpt4 book ai didi

c++ - 如何从双向链表中获取节点内部的有效负载

转载 作者:行者123 更新时间:2023-11-28 07:47:01 25 4
gpt4 key购买 nike

template<class T> class CRevList
{
public:
//...constructor, destructor, etc;
class Node //nested class
{
public:
friend class CRevList;

Node() {m_next = 0; m_prev = 0;}
Node(const T &t) {m_payload = t; m_next = 0; m_prev = 0;}

T Data() {return m_payload;}
const T Data() const {return m_payload;}

private:

Node *m_next;
Node *m_prev;
T m_payload;
};
private: //for original class
Node *m_head, *m_tail; // Head node
unsigned size;
};

我已经多次尝试从原始双向链接类中获取节点的有效负载,不幸的是我遇到了错误。最喜欢:

       error: request for member 'Data' in 'Temp1', which is of non-class type 'CRevList<int>::Node*'

我一定是弄乱了两个类之间的指针或关系。

我试过:

  //Find a node with the specified key
const Node *Find(const T &t) const { }
Node *Find(const T &t) {
Node * Temp1 = m_head;

while(m_tail != Temp1){
if(Temp1.Data() == t){
return Temp1;
}

Temp1 = Temp1->m_next;
}
}

最佳答案

Temp1Node * 类型。因此,您应该调用 Temp1->Data() 而不是 Temp1.Data()

关于c++ - 如何从双向链表中获取节点内部的有效负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14734664/

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