У меня есть назначение, где я должен создавать методы для вставки и удаления узлов в двусвязном списке. Однако я немного ржавый с моим C++. Я получаю сообщение об ошибке от своих передних и задних указателей.Проблема с узлами и связанными списками
LinkedList.h
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
using namespace std;
struct node {
node * prev;
int data;
node * next;
};
class LinkedList {
private:
//pointers to point to front and end of Linked List
static node * front; //the error is coming from here
static node * rear; //the error is coming from here
public:
static void insert_front(int data);
};
#endif
LinkedList.cpp
#include "LinkedList.h"
//insert int to front
void LinkedList::insert_front(int data) {
node *q = nullptr;
//If the list is empty
if (front == nullptr && rear == nullptr) {
q = new node;
q->prev = nullptr;
q->data = data;
q->next = nullptr;
front = q;
rear = q;
q = nullptr;
}
//If there is only one node in list
//...
//If there are at least 2 nodes in list
//...
}
Ошибки я получаю являются:
unresolved external symbol "private: static struct node * LinkedList::front ([email protected]@@[email protected]@A)
unresolved external symbol "private: static struct node * LinkedList::rear ([email protected]@@[email protected]@A)
если удалить статические из частных переменных когда я Разностные их в файле CPP я получаю «нестатический контрольный элемент должен быть по отношению к конкретному объекту»