2
我遇到了一些來自boost graph library Dijkstra example的代碼問題。我改變了它,以便我的版本不使用枚舉和Letter而只是整數。它抱怨for循環和領帶函數,以及除第一個以外的其他領帶調用。C++ Boost圖庫 - Dijkstra示例
Declerations:
typedef std::pair<int, int> Edge;
const int num_edges = num_edge;
Edge edge_array[num_edges];
int weights[num_edges];
int size = 0;
for(itora = edges.begin(); itora != edges.end(); ++itora){
int u = *itora;
++itora;
int v = *itora;
++itora;
weights[size] = *itora;
edge_array[size] = Edge(u,v);
size++;
}
graph_traits<graph_t>::vertex_iterator i, iend;
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
graph_t g(vertices.size());
property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
std::vector<vertex_descriptor> msvc_vertices;
for (boost::tie(i, iend) = vertices(g); i != iend; ++i){
msvc_vertices.push_back(*i);
}
for (std::size_t j = 0; j < num_edges; ++j) {
edge_descriptor e; bool inserted;
boost::tie(e, inserted) = add_edge(msvc_vertices[edge_array[j].first],
msvc_vertices[edge_array[j].second], g);
weightmap[e] = weights[j];
}
不破:
for (boost::tie(i, iend) = vertices(g); i != iend; ++i){
msvc_vertices.push_back(*i);
}
這部分減免:
graph_traits<graph_t>::vertex_iterator xi, xiend;
for (boost::tie(xi, xiend) = vertices(g); xi != xiend; ++xi) {
indexmap[*xi] = c;
name[*xi] = '0' + c;
c++;
}
以下是錯誤:
x.cc: In function 'int main(int, char**)':
x.cc:141: error: no match for call to '(std::vector<int, std::allocator<int> >) (main(int, char**)::graph_t&)'
gmake: *** [x.o] Error 1
任何幫助將不勝感激,我真的不知道錯誤是什麼抱怨...
頂點是導入庫的一部分,std :: pair –
Jim
你知道其他的東西嗎? – Jim
@Jim:我堅持我的原始猜測。你似乎已經改變了引用的代碼,現在我看到'vertices.size()',這似乎確實支持我的理論。你用一個變量'vertices'遮蔽了函數'vertices()',它的類('std :: vector')沒有實現'operator()',這正是錯誤告訴你的。 –