成員,我有一類稱爲邊緣和一個叫頂點C++編譯器錯誤類沒有名爲
在我的邊緣類類有一個頂點的引用稱爲目標。在頂點我發送一個邊緣,並嘗試通過邊緣改變目標,但我有一個類的編譯器錯誤邊緣沒有成員命名目標。
我Edge.h是
#include "Vertex.h"
class Edge
{
public:
Edge *data;
Edge *next;
Vertex *target;
Edge();
Edge(Edge *x);
Edge(Vertex *x);
void print();
};
錯誤是由該代碼Vertex.cpp
Vertex::Vertex(Edge *x)
{
name = x->target->name;
next = x->target->next;
mark = x->target->mark;
previous = NULL;
next = NULL;
}
確切的錯誤造成的,當我試圖編譯頂點
g++ -g -I. -c -o Vertex.o Vertex.cpp
In file included from Vertex.h:3,
from Vertex.cpp:3:
Edge.h:10: error: ISO C++ forbids declaration of ‘Vertex’ with no type
Edge.h:10: error: expected ‘;’ before ‘*’ token
Edge.h:14: error: expected ‘)’ before ‘*’ token
Vertex.cpp: In constructor ‘Vertex::Vertex(Edge*)’:
Vertex.cpp:26: error: ‘class Edge’ has no member named ‘target’
Vertex.cpp:27: error: ‘class Edge’ has no member named ‘target’
Vertex.cpp:28: error: ‘class Edge’ has no member named ‘target’
如果在Edge.cpp中聲明瞭Edge,則該聲明將不可用於Vertex.cpp。 – Will 2010-12-06 05:00:58
你有沒有在Vertex.cpp中引入Edge.h?錯誤可能是「邊緣沒有名爲目標的成員,因爲類型尚未定義」只是有刺。 – Seth 2010-12-06 05:06:42