[英]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::previous
是Type*
,而不是DNode<Type>*
。
You may want to declare both DNode::next
and DNode::previous
as type DNode<Type>*
. 您可能需要将
DNode::next
和DNode::previous
都声明为DNode<Type>*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.