私は学校の課題に取り組んでいますが、私は取り除くことができないという繰り返しのエラーが発生しています。次のエラーが私のコード未解決ノードの無効な型を使用しています
hw_9_1.cpp: In member function ‘void DLinkedList::addNode(Node*)’:
hw_9_1.cpp:32:31: error: invalid use of incomplete type ‘struct DLinkedList::addNode(Node*)::node’
temp = new(struct node);
^
hw_9_1.cpp:32:27: note: forward declaration of ‘struct DLinkedList::addNode(Node*)::node’
temp = new(struct node);
^~~~
hw_9_1.cpp:33:15: error: request for member ‘xy’ in ‘* temp’, which is of non-class type ‘int’
temp->xy = node->xy;
^~
hw_9_1.cpp:33:24: error: expected primary-expression before ‘->’ token
temp->xy = node->xy;
^~
hw_9_1.cpp:34:15: error: request for member ‘next’ in ‘* temp’, which is of non-class type ‘int’
temp->next = NULL;
全体で継続的に繰り返し、私は、ファイルが含まれ、これは、多くの場合、欠落によるものであると言われているが、私は必要なすべてのファイルが含まれていることを確認するために複数回確認されています。誰も私にこれらのエラーの原因となっている別のアイデアを教えてもらえますか?この問題に関連する割り当てのための
マイコードは
#include "std_lib_facilities_4.h"
#include "Simple_window.h"
#include "Graph.h"
struct Node {
Point xy;
Node* next;
Node* prev;
}*start;
class DLinkedList {
public:
Node* head;
Node* tail;
DLinkedList() : head(nullptr), tail(nullptr) {}
void addNode(Node*); // add a Node to the list
Node* removeNode(Point); //remove a Node from the list
};
void DLinkedList::addNode(Node* node) {
if (start == NULL)
{
head=start;
struct node *s, *temp;
temp = new(struct node);
temp->xy = node->xy;
temp->prev=NULL;
temp->next = NULL;
}
struct node *tmp, *q;
int i;
head=start;
temp = new(struct node);
tmp->xy = node->xy;
q->next=tail
if (q->next == NULL)
{
q->next = tmp;
tmp->next = NULL;
tmp->prev = q;
tail->next=temp;
}
}
Node* DLinkedList::removeNode(Point XY) {
struct node *tmp, *q;
/*first element deletion*/
if (start->xy == XY)
{
tmp = start;
start = start->next;
start->prev = NULL;
free(tmp);
return;
}
q = start;
while (q->next->next != NULL)
{
/*Element deleted in between*/
if (q->next->xy == XY)
{
tmp = q->next;
q->next = tmp->next;
tmp->next->prev = q;
free(tmp);
return;
}
q = q->next;
}
/*last element deleted*/
if (q->next->xy == XY)
{
tmp = q->next;
free(tmp);
q->next = NULL;
return;
}
}
struct DLL : Shape { // Doubly Linked List
void add(Point p) { Shape::add(p); }
void set_point(int i,Point p) { Shape::set_point(i,p); }
void draw_lines() const;
Point last_removed_point;
DLinkedList this_list;
private:
};
をしたいですか? –
あなたは 'c'と' C++ '構文を混ぜているようです。 'struct node'の代わりに' Node'を試してみてください。 – 4386427