我知道还有其他一些类似的帖子,但是我已经在这个错误上一个多小时了,无法弄清楚。这是给麻烦的代码
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 重载。
谢谢你的帮助!