简体   繁体   中英

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

I'm getting the following error in VS2015. It is not obvious to me as to what I'm messing up with the templates.

Any pointer(s) is really appreciated!

Error C2440 '=': cannot convert from 'int *' to '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 is of type Type* , not DNode<Type>* .

You may want to declare both DNode::next and DNode::previous as type DNode<Type>* .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM