簡體   English   中英

Boost圖形轉換錯誤

[英]Boost graph conversion error

我正在使用boost庫創建一個簡單的圖,並嘗試遍歷頂點和邊緣。 但是我收到以下錯誤,其中代碼可以遍歷所有頂點,但是當我添加負責遍歷邊緣的最后一段代碼時,存在編譯問題:

錯誤:從'std :: pair,boost :: detail :: out_edge_iter>轉換,long unsigned int,boost :: detail :: edge_desc_impl,long int>,boost :: adjacency_list>,boost :: detail :: adj_list_edge_iterator,boost :: detail :: out_edge_iter>,長無符號整數,boost :: detail :: edge_desc_impl,long int>,boost :: adjacency_list>>到非標量類型'std :: pair,boost :: detail :: out_edge_iter < __gnu_cxx :: __ normal_iterator *,std :: vector,std :: allocator>>>,long unsigned int,boost :: detail :: edge_desc_impl,long int>,boost :: adjacency_list <>>,boost :: detail :: adj_list_edge_iterator ,boost :: detail :: out_edge_iter <__ gnu_cxx :: __ normal_iterator *,std :: vector,std :: allocator>>>,long unsigned int,boost :: detail :: edge_desc_impl,long int>,boost :: adjacency_list <> >>'請求boost :: adjacency_list <> :: edge_iterator> es = boost :: edges(g);

這是我的代碼

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
int main()
{
    using namespace std;
    using namespace boost;

   typedef adjacency_list< listS, vecS, directedS > digraph;

   // instantiate a digraph object with 8 vertices
   digraph g(8);

   // add some edges
   add_edge(0, 1, g);
   add_edge(1, 5, g);
   add_edge(5, 6, g);
   add_edge(2, 3, g);
   add_edge(2, 4, g);
   add_edge(3, 5, g);
   add_edge(4, 5, g);
   add_edge(5, 7, g);

   // represent graph in DOT format and send to cout
   write_graphviz(cout, g);


   std::cout<< "+++++++++++++++++++++++++++++++++++++\n";
   std::cout<<"Print Vertices\n";

   std::pair<boost::adjacency_list<>::vertex_iterator,
      boost::adjacency_list<>::vertex_iterator> vs = boost::vertices(g);

    std::copy(vs.first, vs.second,std::ostream_iterator<boost::adjacency_list<>::vertex_descriptor>{
        std::cout, "\n"});


    std::cout<< "+++++++++++++++++++++++++++++++++++++\n";
    std::cout<<"Print Edges\n";

    std::pair<boost::adjacency_list<>::edge_iterator,
        boost::adjacency_list<>::edge_iterator> es = boost::edges(g);

      std::copy(es.first, es.second,std::ostream_iterator<boost::adjacency_list<>::edge_descriptor>{
          std::cout, "\n"});

   return 0;
}

您正在將edges的結果分配給不兼容類型的變量。 代替

std::pair<boost::adjacency_list<>::edge_iterator,
    boost::adjacency_list<>::edge_iterator> es = boost::edges(g);

采用

auto es = boost::edges(g);

要么

std::pair<digraph::edge_iterator, digraph::edge_iterator> es = boost::edges(g);

更多詳細信息:您的digraph類型為adjacency_list指定了三個模板參數:

typedef adjacency_list< listS, vecS, directedS > digraph;

可以使用這種類型的參數調用edges ,但是您必須指定函數的EdgeIterator模板參數必須為boost::adjacency_list<>::edge_iterator ,就像g屬於adjacency_list<>而不是adjacency_list<listS, vecS, directedS> 顯然,該轉換對adjacency_list<>::vertex_iterator有效,但對adjacency_list<>::edge_iterator

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM