每个人。我是 BOOST GRAPH LIBRARY 的新人。我试图创建一个试用图来表示我的团队中的关系,但它没有用。代码如下:
// Construct a graph that shows relationship in Edexteam
#include<iostream>
#include<utility>
#include<fstream>
#include<boost/graph/graph_traits.hpp>
#include<boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
int main(){
// Construct data about our graph
enum Edexteam {ProfNachiket, Lam, Son, Shubham, Girl1, Girl2, Num};
const int num_members = Num;
const char* name[] = {"Prof Nachiket", "Lam", "Son", "Shubham","Girl1","Girl2 "};
// Configure some general characteristics for our graph
typedef adjacency_list<vecS,vecS,bidirectionalS> EdexteamGraph;
// Construct edges
typedef pair<int,int> RelationInEdexteam;
RelationInEdexteam relation[] = {RelationInEdexteam(Lam,Son),RelationInEdexteam(ProfNachiket,Son),
RelationInEdexteam(Girl1,Girl2),RelationInEdexteam(ProfNachiket,Shubham)};
// Construct graph by using edge iterator constructor
EdexteamGraph graph(relation, relation + sizeof(relation) / sizeof(RelationInEdexteam), num_members);
// Get the property map for vertex indices
typedef property_map<EdexteamGraph,vertex_index_t> VerIndex;
VerIndex index = get(vertex_index,graph);
cout << "vertices(graph) = ";
typedef graph_traits<EdexteamGraph>::vertex_iterator vertex_iter;
pair<vertex_iter, vertex_iter> vp;
for (vp = vertices(graph); vp.first != vp.second; ++vp.first)
std::cout << index[*vp.first] << " ";
std::cout << std::endl;
return 0;
}
然后我收到错误消息
trygraph.cpp: In function ‘int main()’:
trygraph.cpp:41:43: error: conversion from ‘boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>, boost::vertex_index_t>::type {aka boost::vec_adj_list_vertex_id_map<boost::no_property, long unsigned int>}’ to non-scalar type ‘VerIndex {aka boost::property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>, boost::vertex_index_t>}’ requested
trygraph.cpp:46:34: error: no match for ‘operator[]’ in ‘index[((boost::iterator_facade<boost::range_detail::integer_iterator<long unsigned int>, long unsigned int, boost::random_access_traversal_tag, long unsigned int, long int>*)(& vp.std::pair<boost::range_detail::integer_iterator<long unsigned int>, boost::range_detail::integer_iterator<long unsigned int> >::first))->boost::iterator_facade<I, V, TC, R, D>::operator* [with Derived = boost::range_detail::integer_iterator<long unsigned int>, Value = long unsigned int, CategoryOrTraversal = boost::random_access_traversal_tag, Reference = long unsigned int, Difference = long int, boost::iterator_facade<I, V, TC, R, D>::reference = long unsigned int]()]’
我真的不知道发生了什么事。请帮我指出来。我真的很感激