简体   繁体   English

错误c2440&#39;=&#39;无法从int *转换为Type <T> *

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

I'm getting the following error in VS2015. 我在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 *' 错误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 is of type Type* , not DNode<Type>* . DNode::previousType* ,而不是DNode<Type>*

You may want to declare both DNode::next and DNode::previous as type DNode<Type>* . 您可能需要将DNode::nextDNode::previous都声明为DNode<Type>*

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:C2440“返回”:无法从“int”转换为 T - error: C2440 'return': cannot convert from 'int' to T 错误C2440:“返回”:无法从“ int [2]”转换为“ int(&amp;&amp;)[2]” - Error C2440: 'return' : cannot convert from 'int [2]' to 'int (&&)[2]' decltype 错误 C2440 无法从“int *”转换为“int *&amp;” - decltype error C2440 cannot convert from 'int *' to 'int *&' 错误C2440:“ =”:无法从“ int *”转换为“ int **” - error C2440: '=' : cannot convert from 'int *' to 'int **' 错误C2440:“ =”:无法从“ int”转换为“ char [5]” - error C2440: '=' : cannot convert from 'int' to 'char [5]' 错误C2440:&#39;=&#39;:无法从&#39;char *(__ cdecl *)(int,int)&#39;转换为en&#39;GetItemText_t&#39; - error C2440: '=' : cannot convert from 'char *(__cdecl *)(int,int)' to en 'GetItemText_t' 错误C2440&#39;=&#39;:无法从&#39;cli :: array转换 <Type> ^&#39;至&#39;wchar_t&#39; - Error C2440 '=' : cannot convert from 'cli::array<Type> ^' to 'wchar_t' C2440&#39;=&#39;无法从&#39;int&#39;转换为&#39;BST <int> ::节点* - C2440 '=' cannot convert from 'int' to 'BST<int>::Node* 错误C2440:&#39;初始化&#39;:无法从&#39;const int&#39;转换为&#39;int *&#39; - error C2440: 'initializing' : cannot convert from 'const int' to 'int *' 抑制 State 错误 C2440 'return': cannot convert from '_Ty2 *' to 'std::pair<t *,unsigned int> '</t> - Suppression State Error C2440 'return': cannot convert from '_Ty2 *' to 'std::pair<T *,unsigned int>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM