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;
}
}
答案 0 :(得分:1)
Temp1
的类型为Node *
。因此,您应该拨打Temp1->Data()
而不是Temp1.Data()
。