I have a function that inserts a new node at the tail end of a linkedlist:
void LinkedList::insert(Node* previousPtr, Node::value_type& newData)
{
Node *insertPtr;
insertPtr->setData(newData);
insertPtr->setNext(previousPtr->getNextPtr());
previousPtr->setNext(insertPtr);
}
In another function I am trying to call the previous:
void copyData(Node* sourcePtr, Node*& headPtr, Node*& tailPtr)
{
...//other code
insert(tailPtr, sourcePtr->getData());
...//other code
}
The compiler gives an error of: “insert” undeclared first use this function. What am I missing?
You are missing something like
or you could make copydata a member of the LinkedList class: