无法弄清楚我输入的参数是否错误或代码是否有问题

时间:2019-10-16 07:55:10

标签: c++

因此,我几乎没有开始学习链表,我做了一个函数,将头插入链表。我无法弄清楚的问题是我输入的参数有误还是我的代码有错误。

节点结构:

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函数:

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
}

主要:

{
    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;
}

错误:未定义对'node :: node(node *,int const&)'的引用

0 个答案:

没有答案
相关问题