前提・実現したいこと
C++でqueue(dataフィールドと前後の構造体を指すpointerのフィールドが2つある)の後ろに新しい文字を含んだ構造体を追加したいのですが、以下のソースコードのerror exception!!のコメントがあるところに矢印が引っ張ってあり、以下のエラーメッセージが出て実行出来ません。ここでのエラーメッセージの意味と、具体的にコードの何を改善すれば良いのかアドバイスをお願いいたします。
発生している問題・エラーメッセージ
First-chance exception at 0x009D6016 in template.exe: 0xC0000005: Access violation writing location 0x0000001C. If there is a handler for this exception, the program may be safely continued.
該当のソースコード
header file
C++
1#include <string> //this allows you to declare and use strings 2#include <iostream> 3using namespace std; 4 5struct qNode 6{ 7 string data; 8 qNode* next; 9 qNode* previous; 10} ; 11 12class CBQueue 13{ public: 14 CBQueue(); 15 int getSize() const; 16 bool isEmpty() const; 17 void enqueue(string s); 18 void printF2B() const; 19 void printB2F() const; 20 string dequeue(); 21 void cut(string s); 22 string bail(); 23 void B2F(); 24 bool equals(CBQueue otherQ) const; 25 private: 26 qNode* temp; 27 qNode* front; 28 qNode* rear; 29 int size; 30} ; 31 32
cpp file
C++
1CBQueue::CBQueue() 2//preondition: none 3//postcondition: set is empty 4{ 5 front = NULL; 6 rear = NULL; 7 size = 0; 8} 9 10... 11 12void CBQueue::enqueue(string s) 13//preondition: none 14//postcondition: add a new structure containing string s to the rear of the queue 15{ 16 temp = new qNode; 17 temp->data = s; 18 temp->next = NULL; 19 20 if (size == 0) 21 { 22 front = rear = temp; 23 temp->previous = NULL; 24 } 25//ERROR EXCEPTION!! 26 else 27 { 28 rear->next = temp; // ERROR EXCEPTION!! 29 temp->previous = rear; 30 } 31 32 rear = temp; 33 size++; 34} 35
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
Microsoft (macOS10.12.6 仮想環境)
Microsoft Visual Studio 2013
メッセージとしてはデバッガで実行してるように見えるのですが、コンパイル出来ないとデバッグは出来ません。よく分かりません。