g++ -Wall -c -std=gnu++11 "linked_list.h" (in directory: /linked_list)
linked_list.h: In member function ‘void Linked::append(Node&)’:
linked_list.h:40:11: error: base operand of ‘->’ has non-pointer type ‘Node’
last->prev = tmp->prev;
^
linked_list.h:41:11: error: base operand of ‘->’ has non-pointer type ‘Node’
last->next = tmp->next;
^
linked_list.h:42:17: error: cannot convert ‘Node’ to ‘Node*’ in assignment
tmp->next = last;
^
linked_list.h:43:18: error: cannot convert ‘Node’ to ‘Node*’ in assignment
tail->prev = last;
^
Compilation failed.
I assumed last->prev is a pointer and so is tmp, so an assignment should be feasible.
Any clues would be appreciated?
Lines 40-41: last is passed by reference it is not a pointer. last->member is not valid. Use last.member.
Lines 42-43: Again, last is passed by reference. It is not a pointer. tmp->next and tail->prev are pointers. You can't assign a non-pointer type to a pointer. Use &last.
thanks for the help, I'll stick to pointers as arithmetic is possible.
Pointer arithmetic for most implementations of a linked list, yours included, would be a horrible mistake. Nevertheless, I'd stick to pointers for consistency internally. Client code, of course, should have no need to know about Nodes, pointers or not.
thanks for the tips, I've made my linked list somewhat more generic by making the data within Node a type. When I attempt to append to the end of the list I get the following compile error:
1 2 3 4 5 6 7 8 9 10
g++ -c -Wall -std=gnu++11 track_score.cpp
track_score.cpp: In function ‘int main()’:
track_score.cpp:12:15: error: request for member ‘append’ in ‘score_sheet’, which is of non-class type ‘LinkedList<int>(Node<int>)’
score_sheet.append(Node<Item>);
^
track_score.cpp:12:32: error: expected primary-expression before ‘)’ token
score_sheet.append(Node<Item>);
^
makefile:12: recipe for target 'track_score.o' failed
make: *** [track_score.o] Error 1