简体   繁体   中英

C++ Boost Graph Library - Dijkstra Example

I am having some problems with the code from boost graph library Dijkstra example . I changed it so that my version doesn't use enums and Letter rather just integers. It complains about the for loop and the tie function, as well as other tie calls except for the first.

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];
  }

Does not break:

for (boost::tie(i, iend) = vertices(g); i != iend; ++i){
  msvc_vertices.push_back(*i);
}

This part breaks:

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++;
}

Here is the error:

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

Any help would be greatly appreciated, I don't really know what the error is complaining about...

您是否在未引用的代码中的某处创建了局部变量std::vector<int> vertices

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM