我知道有一些其他的帖子是這樣,但現在我已經對這個單一的錯誤了一個多小時,不能弄明白。這裏是一個的給麻煩C++不明原因的錯誤:錯誤:之前預計初始「和」令牌
istream& operator>>(istream& in, UndirectedGraph& g)
{
int numVerticies;
in >> numVerticies;
g = UndirectedGraph(numVerticies);
for(int i = 0; i < numVerticies; i++)
{
int temp;
in >> temp;
if(temp != i)
{
g.linkedAdjacencyList[i]->value = temp;
}
}
int edges;
in >> edges;
g.edges = edges;
for(int i = 0; i < edges; i++)
{
int first;
int second;
in >> first >> second;
addEdge(first, second);
}
return in;
}
ostream& operator<<(ostream& out, UndirectedGraph& g)
{
out << g.numVerticies << endl;
for(int i = 0; i < g.numVerticies; i++)
{
out << g.linkedAdjacencyList[i] << " ";
}
out << endl;
out << g.edges << endl;
for(int i = 0; i < g.numVerticies; i++)
{
out << linkedAdjacencyList[i]->value;
Node* whereto;
whereto = linkedAdjacencyList[i]->adj;
while(whereto->adj != NULL)
{
out << " " << whereto->value;
whereto->adj = whereto->adj->adj;
}
}
return out;
}
int main()
{
ifstream inFile;
inFile.open("hw8.in");
UndirectedGraph graph;
inFile >> graph;
...
這裏的代碼,錯誤都在線1和28,與istream和ostream的超載。
感謝您的幫助!
什麼是線1和28? – 2011-04-12 13:11:51
@Daniel istream和ostream聲明 – jlehenbauer 2011-04-12 14:06:47