I am implementing a doubly linked list in C++ and I am trying to add a node.append(node2)
method to the node class which will link a new node object (node2) to the previous one (node). I receive an expected primary-expression before ‘;’ token
error on the line node->previous = Node;
. How do I get the address of the object within its class definition so that I can assign it to node->previous
?
class Node {
public:
int value;
Node *next;//points to next node.
Node *previous;//doubly linked list.
void append(Node *node) {
next = node;
node->previous = Node;
node->next = NULL;
}
};