'Copy Constructor Error With a Template Linked List Class : no matching function for call to 'Node<int>::Node()'
I'm trying to make a copy constructor for a linked list but I'm not sure how to fix this error and I've been looking for hours. The error is:
no matching function for call to 'Node::Node()'
Here is the code:
template <class T>
class Node //node is the name of class, not specific
{
public:
T data; //t data allows for any type of variable
Node *next; //pointer to a node
Node(T Data) //assign data value
{
data = Data; //makes data = NV parameter
next = nullptr; //makes next = to nullptr
}
};
template <class T>
class LinkedList
{
private:
Node<T> * head, *tail; //// typedef Node* head // -- head = Node* -- //// typedef Node* nodePtr = Node* ////
public:
LinkedList() //constructor for Linked List
{
head = nullptr;
tail = nullptr;
}
LinkedList(LinkedList& copy)
{
head = nullptr;
tail = nullptr;
Node<T>* Curr = copy.head;
while(Curr) //while not at end of list
{
//val = copyHead->data;
Node<T>* newCpy = new Node<T>;
newCpy->data = Curr->data;
newCpy->next = nullptr;
if(head == nullptr)
{
head = tail = newCpy;
}
else
{
tail->next = newCpy;
tail = newCpy;
}
}
}
~LinkedList()
{
while (head)
{
Node<T>* tmp = head;
head = head->next;
delete(tmp);
}
head = nullptr;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
