2015-08-26 224 views
0

我在VS2015中收到以下錯誤。 對我而言,搞亂模板並不明顯。錯誤c2440'='無法從int *轉換爲類型<T> *

任何指針真的很感謝!

錯誤C2440 '=':不能從 '詮釋*' 轉換爲 'DNode *'

template<class Type> 
    class DNode <- *** THIS IS THE TYPE *** 
    { 
    public: 
     Type *next; 
     Type *previous; 
     Type value; 

     DNode(Type valueParam) 
     { 
      value = valueParam; 
      next = previous = NULL; 
     } 
    }; 

    template<class T> 
    class DLinkedList 
    { 
     DNode<T> *head; 
     DNode<T> *tail; 

    public: 
     DLinkedList() 
     { 
      head = tail = NULL; 
     } 

     T pop_tail() 
     { 
      if (tail == NULL) return -1; 
      T value; 
      if (head == tail) 
      { 
       value = tail->value; 
       free(tail); 
       head = tail = NULL; 
       return value; 
      } 
      else 
      { 
       DNode<T> *ptr = tail; 
       value = tail->value; 
       tail = tail->previous; <-- *** THIS LINE THROWS ERR *** 
       tail->next = NULL; 
       free(ptr); 
       return value; 
      } 
     } 
    } 

回答

4

DNode::previous是類型Type*,不DNode<Type>*的。

您可能想要聲明DNode::nextDNode::previousDNode<Type>*

+0

Aw。說得通。謝謝!我會在8分鐘內將此標記爲答案 –

相關問題