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

1 回答 1

1

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

于 2013-02-06T17:08:54.067 回答