So, I barely started learning about linked lists, and I made a a function that inserts a head into the linked list. The problem I'm having trouble figuring out is if I'm entering in the arguments incorrectly, or if my code has some errors.
node struct:
template<typename T>
struct node
{
public:
node(node* next = nullptr, const T& item = T());
template<typename U>
friend ostream& operator <<(ostream& outs, const node<U> &print_me);
T _item; //crate
node* next; //label
};
insert_head function:
node<T>* insert_head(node<T> *&head, const T& insert_this)
{
//create new dynamic variable
node<T>* temp = new node<T>; //IT SHOWS THAT THE ERROR OCCURS HERE
//temp takes in the insert_this item
temp->_item = insert_this;
//temp points to the head so it doesn't lose the location
temp->next = head;
//head points back to temp
head = temp;
return head; //returns back the head of the list
}
Main:
{
node<int>* head_ptr = nullptr;
for(node<int>* nPtr = head_ptr; nPtr != nullptr; nPtr = nPtr->next)
{
insert_head(head_ptr, 7); //insert integer 5 into the head
PrintList(head_ptr); //print the linked list
}
return 0;
}
Error: undefined reference to 'node::node(node*, int const&)'