【发布时间】:2014-10-28 17:56:54
【问题描述】:
这是我要编译的代码:
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>*’
我不明白问题出在哪里。
【问题讨论】:
-
您的代码中没有向量。
-
你的意思是使用
std::vector< std::pair<int, float> >?