Reputation: 747
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;
}
}
}
Upvotes: 0
Views: 782
Reputation: 23058
DNode::previous
is of type Type*
, not DNode<Type>*
.
You may want to declare both DNode::next
and DNode::previous
as type DNode<Type>*
.
Upvotes: 4