c++ - Boost.Graph 示例 4 dynamic_properties 错误

标签 c++ qt boost graph

为 QT 运行 Boost.Graph 示例 4 会出现流动错误:

对“(boost::dynamic_properties)(std::bacic_ostream>&,unsigned int)”graphvic.hpp 的调用不匹配

错误发生在 graphvic.hpp 的以下行:

for(boost::tie(i,end) = vertices(g); i != end; ++i) {
      out << escape_dot_string(get(vertex_id, *i));
      vpw(out, *i); //print vertex attributes
      out << ";" << std::endl;
}

我无法找出错误的原因。下面是 Boost.Graph 示例 4 代码。请帮助我。

typedef boost::adjacency_list
  <   
    boost::vecS,  
    boost::vecS,  
    boost::undirectedS,  
    boost::property<boost::vertex_name_t,std::string>,   
    boost::property<boost::edge_weight_t,double>,   
    boost::property<boost::graph_name_t,std::string>
  > Graph;

  Graph  g;

  std::vector<std::string> names;
  names.push_back("Mr_A");
  names.push_back("Mrs_B");
  names.push_back("Dr_C");
  names.push_back("Prof_D");

  const Graph::vertex_descriptor v0 = boost::add_vertex(names[0],g);
  const Graph::vertex_descriptor v1 = boost::add_vertex(names[1],g);
  const Graph::vertex_descriptor v2 = boost::add_vertex(names[2],g);
  const Graph::vertex_descriptor v3 = boost::add_vertex(names[3],g);

  std::vector<double> frequencies;
  frequencies.push_back(0.9);
  frequencies.push_back(0.5);
  frequencies.push_back(0.6);
  frequencies.push_back(0.1);

  boost::add_edge(v0,v1,frequencies[0],g);
  boost::add_edge(v1,v2,frequencies[1],g);
  boost::add_edge(v2,v3,frequencies[2],g);
  boost::add_edge(v0,v3,frequencies[3],g);

  //Writing graph to file
  {
    std::ofstream f("test.dot");

    boost::dynamic_properties p;
    p.property("label", boost::get(boost::edge_weight, g));
    p.property("weight", boost::get(boost::edge_weight, g));
    p.property("node_id", boost::get(boost::vertex_name, g));
    boost::write_graphviz(f,g,p);
    f.close();
  }

谢谢, 普拉卡什

最佳答案

您可以将 write_graphviz 更改为 write_graphviz_dp 并重试,它应该可以工作,但是,我不知道下面的故事。有人可以给出一些解释吗?

关于c++ - Boost.Graph 示例 4 dynamic_properties 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5632378/

相关文章:

c++ - 在 boost for_each 中运行成员函数 vector

C++20 在 g++10 : generator not defined

c++ - 未构造对象的调用方法 : Legal?

c++ - msys2 静态 QT undefined reference 问题

qt - 如何为 QMacStyle 获取整个 Qt 样式表

c++ - 类类型未知时调用成员函数

c++ - Mac 独立 Xcode c++ 命令行项目

c++ - Valgrind 运行缓慢

c++ - Q_DECLARE_METATYPE 抛出缺少类型说明符错误

c++ - boost::lambda 中 boost::bind 的嵌套用法不起作用