二重リンクされたリストのノードを挿入したり削除したりするためのメソッドを作成することになっています。しかし、私は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)
私はプライベート変数から静的を削除する場合私が参照するとき
node* LinkedList::front = nullptr;
node* LinkedList::rear = nullptr;
我々だけ呼び出すことができます静的クラス:あなたはあなたのcppファイル内の静的変数を初期化する必要があり、私は