undeclared first use this function - compile error C++ LinkedList
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);
}
开发者_C百科
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
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)
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( ... );
精彩评论