Please delete.
I want to implement a linked list. Unfortunately I'm not sure whether I'm on the right track.
#include <iostream>
using namespace std;
class Node {
friend class List;
public:
int value;
private:
Node *next;
};
class List {
public:
List ();
~List ();
Node * first() const;
Node * next(const Node * n) const;
void append (int i);
Node* head;
};
List::List() {
Node* head = new Node();
}
List::~List() {
while(head != NULL) {
Node * n = head->next;
delete head;
head = n;
}
}
Node * List::first() const {
return head; // this could also be wrong
}
Node * List::next(const Node * n) const {
return n + 1; // ERROR
}
void List::append(int i) {
Node * n = new Node;
n->value = i;
n->next = head;
head = n;
}
int main(void) {
List list;
list.append(10);
return 0;
}
When I try to return an element in next()
I get this error:
In member function ‘Node* List::next(const Node*) const’:|
error: invalid conversion from ‘const Node*’ to ‘Node*’ [-fpermissive]|
Could somebody please help me?
EDIT:
I've updated the error-line.