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;
}
}