The error means that somewhere you have a LinkedList list declared not as a pointer, to which you assign a new LinkedList()
which is of type LinkedList*
(and not LinkedList
). It should be:
LinkedList* list = new LinkedList(); // I declare a pointer to a list
list->addAtFront(0); // I call a method on a pointer to an object
or
LinkedList list;
list.addAtFront(0);
They are two different types which are allocated in two different storages and this is important, keep reading.
What I see more importantly is that when you use dynamically allocated memory you should take case of actually allocate on heap objects that should persist the scope in which they are declared.
More specifically, this:
{
Node temp;
..
head = &temp;
..
}
This will cause problems because temp
is declared as automatic storage on stack, which means that once you obtained its address and assign it to head
or tail
or whatever, that address won't be valid anymore once the scope exited. You should allocate it on heap:
Node temp = new Node(value, id);
head = temp;
tail = temp;
++size;
Mind that this requires that you clean up memory by yourself from the heap when the Node
is not needed anymore.