Reputation: 27
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?
Upvotes: 0
Views: 619
Reputation: 12264
You are missing something like
some_linked_list->insert(some_node_ptr, ...)
or you could make copydata a member of the LinkedList class:
void LinkedList::copyData(Node* sourcePtr, Node*& headPtr, Node*& tailPtr)
Upvotes: 2
Reputation: 76918
LinkedList::insert
is a method in your LinkedList
class. You would need an instance of that class to call it.
LinkedList *myLinkedList = new LinkedList();
myLinkedList->insert( ... );
Upvotes: 2