Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It says error at every new node I\'ve created. inventory::inventory(const invent

ID: 3637599 • Letter: I

Question

It says error at every new node I've created.

inventory::inventory(const inventory& inven)
{
    if (inven.head == 0)
        head = 0;
    else
    {
        //copy first node
        head = new node;     // ----> Error here, it says "no appropriate default constructor available"
        assert(head != 0); //check allocation
        head->data = inven.head->data;

        //copy the rest of the list
        node * destNode = head;                //points to the last node in new list
        node * srcNode = inven.head->next; //points to node in aList
        while(srcNode != 0)
        {
            destNode->next = new node;
            assert(destNode->next != 0); //check allocation
            destNode = destNode->next;
            destNode->data = srcNode->data;

            srcNode = srcNode->next;
        }
        destNode->next = 0;
    }       
}

Explanation / Answer

The problem is in this part of insert:

where the node contains an Object. To construct that, the Object needs a default constructor.

Perhaps you can add a constructor to node that copies the value it has to store? That would make it, for example:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote