Reputation: 127
Okay, so I have a Linked List struct set up as so:
struct ListNode {
ListNode* next;
int data;
ListNode(int in) {
data = in;
next = NULL;
}
ListNode(int in, ListNode* n) {
data = in;
next = n;
}
};
Along with an insert function:
bool insertNode(ListNode **head, int position, int data) {
if (position == 0) {
ListNode *element = new ListNode(data, *head->next);
*head->next = element;
return true;
}
else if (head == NULL)
return false;
else {
insertNode(head->next, position-1, data);
}
}
How would I access the next element of head? With the code that currently is in place, I get this error message:
request for member ‘next’ in ‘* head’, which is of non-class type ‘ListNode*’
Upvotes: 0
Views: 952
Reputation: 1275
This should do the trick
(*head)->next
EDIT: For more information about operator priority http://en.cppreference.com/w/cpp/language/operator_precedence
Upvotes: 4