I am trying to make a node for a doubly linked list in c++, but experiencing some problems with the constructor. I have the following simplyfied header file:
class Node{
public:
Node();
private:
int data;
Node* next;
Node* previous;
};
My .cpp file looks as the following:
#include <iostream>
#include <cstdlib>
using namespace std;
int data;
Node* next;
Node* previous;
Node::Node(){
data = 0;
next = NULL;
previous = NULL;
}
I get the following error when compiling this: "Node does not name a type."
I have also tried to use 'struct' to create the Node:
struct Node{
int data;
Node* next;
Node* previous;
}
But this however gives me another error on the constructor in the cpp file: "definition of implicitly-declared ...."
How can I make this program compile without error messages by using a constructor and variables, and what am I doing wrong?