-2
這裏是我試圖編譯代碼:的push_back在結構向量不工作
int main(){
struct node{
pair<int, float>* neighbors;
};
pair<int, float> wvertex;
int VCount, v1, v2;
float w;
cin >> VCount;
node* graph_nodes[VCount+1];
while(cin >> v1){
cin >> v2 >> w;
wvertex.first = v2;
wvertex.second = w;
graph_nodes[v1]->neighbors.push_back(wvertex);
}
return 0;
}
但是,它在編譯時給出了一個錯誤說:
In function ‘int main()’:
error: request for member ‘push_back’ in ‘graph_nodes[v1]->main()::node::neighbors’, which is of non-class type ‘std::pair<int, float>*’
我無法理解問題在哪裏。
代碼中沒有矢量。 – juanchopanza 2014-09-04 05:19:25
你的意思是使用'std :: vector>'? –
2014-09-04 05:22:48