【发布时间】:2018-07-04 20:05:39
【问题描述】:
我有一个这样定义的虚拟类:
class Graph
{
friend std::ostream& operator<<(std::ostream&, const ArchGraph &);
struct VertexProperty;
struct EdgeProperty;
typedef boost::vecS vertex_selector;
typedef boost::vecS edge_selector;
typedef boost::property<boost::vertex_name_t, VertexProperty> vertex_property;
typedef boost::property<boost::edge_name_t, EdgeProperty> edge_property;
typedef boost::adjacency_list<
vertex_selector, edge_selector, boost::bidirectionalS,
vertex_property, edge_property> adjacency_type;
typedef size_t size_type;
struct VertexProperty {
size_type id;
};
struct EdgeProperty {
adjacency_type::edges_size_type index;
size_type id;
};
public:
void foo() const;
private:
adjacency_type _adj;
};
在它的foo 方法中,我尝试遍历邻接列表_adj 中的所有顶点并打印每个顶点属性的id 成员:
void Graph::foo() const
{
for (auto v : boost::make_iterator_range(boost::vertices(_adj))) {
std::cout << _adj[v].id;
}
}
这无法编译,显然_adj[v] 的类型为const struct boost::no_property,这不是我所期望的。
这对我来说似乎有点荒谬,因为似乎有很多例子漂浮在周围,似乎正是采用这种方法。
我正在使用 Boost 1.67.0,有人可以告诉我我在这里做错了什么吗?文档在这方面不是很有帮助。
【问题讨论】:
标签: c++ boost boost-graph