错误 c2440 '='无法从 int * 转换为类型<T> *

Error c2440 '=' cannot convert from int * to Type<T> *

本文关键字:转换 类型 gt lt c2440 错误 int      更新时间:2023-10-16

我在VS2015中得到以下错误。我不清楚我在模板中搞砸了什么。

任何指针(s)是真的很感激!

错误C2440 '=':无法从'int *'转换为'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;
            }
        }
    }

DNode::previous的类型是Type*,而不是DNode<Type>*

您可能希望将DNode::nextDNode::previous声明为DNode<Type>*类型。