First of all, this
is a pointer, not a reference, so you need to replace all this.
with this->
.
Secondly, you cannot store an instance of a class inside that class because the size of the class would be incalculable. You can only store pointers or references to the class inside the class itself, because the compiler can calculate the size of a pointer or reference to any class without having to have any details of the class (because these pointers/references are all the same size regardless of the underlying object). Change
Node next;
Node previous;
to
Node* next;
Node* previous;
// or Node* next, *prev;
And change
void insert(Node node)
to
void insert(Node* node)
You also need to initialise the member pointers to NULL
(not null
) in the constructor of your object (because C++ doesn't initialise variables that are intrinsic (built-in) types (like pointers) for you):
Node(int value) {
this->previous = NULL;
this->next = NULL; // or: previous = next = NULL;
this->value = value;
this->min = value; // or: this->value = min = value;
}
// or with initialiser lists (but don't get confused if you don't understand)
// Node(int value) : previous(), next(), value(value), min(value) { }
Additionally, I (like everyone else) have deduced (from your use of objects like they are references and your use null
instead of NULL
and of the words 'method' and 'attribute') that you are a Java or C# programmer learning C++. Please stop now and read a good book on C++, because C++ is nothing like Java or C#, and if you try to use your C#/Java experience when programming C++ then you will only end up ripping your own head off out of frustration.