I have a purpose where I have to create methods for inserting and deleting nodes in a doubly linked list. However, I'm a little rusty with my C ++. I get an error message from my front and back pointers.
LinkedList.h
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
using namespace std;
struct node {
node * prev;
int data;
node * next;
};
class LinkedList {
private:
static node * front;
static node * rear;
public:
static void insert_front(int data);
};
#endif
LinkedList.cpp
#include "LinkedList.h"
void LinkedList::insert_front(int data) {
node *q = nullptr;
if (front == nullptr && rear == nullptr) {
q = new node;
q->prev = nullptr;
q->data = data;
q->next = nullptr;
front = q;
rear = q;
q = nullptr;
}
}
The errors I get are the following:
unresolved external symbol "private: static struct node * LinkedList::front (?front@LinkedList@@0PAUnode@@A)
unresolved external symbol "private: static struct node * LinkedList::rear (?rear@LinkedList@@0PAUnode@@A)
if I delete static data from private variables when I refer to them in the cpp file, I get a "link to a non-static element link to a specific object"
source
share