[英]To initialize a filtered_graph object in constructor after graph is defined in BOOST GRAPH
我在初始化boost中的filter_graph有一个查询。
这是我的代码,
// predicate
template <typename TGraph>
struct edge_predicate
{
bool operator()(const typename boost::graph_traits<TGraph>::edge_descriptor& v) const
{
return true //testing purpose
}
};
// class
class A{
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t;
typedef boost::filtered_graph < Graph_t , edge_predicate > FilteredGraphType_t;
// members
Graph G;
FilteredGraphType_t FG() ; // empty filter graph ???
// constructor for A
template < ..typename list >
A ( ... input iterators list... )
{
fill the graph G with some values passed in constructor argument list.
// predicate
edge_predicate< Graph_t > EPred;
//filtered_graph
FilteredGraphType_t FG( G, EPred); // I am passing on edge predicate.
}
};
// member function:
FilteredGraphType_t& get_filtered_graph()
{
return FG;
}
问题:
FG是A类的成员,G也是A的成员。最初,G是空对象,所以我想FG也是如此。
在A的构造函数中,我用自己的逻辑(例如,顶点数,边数等)填充GraphG。 现在,我想在图G(填充G之后)上创建一个过滤器FG (它是A类的成员 )。
我想要这个的原因是,此筛选后的图形作为对其他类构造函数的引用传递。 这迫使我使FG成为类A的成员。(我可以在A本身的构造函数中创建过滤器图的新实例,但不会达到将引用返回给FG的目的。)
我希望这很清楚。 请建议
您可以使代码编译并正常运行。 尝试按如下所示重新组织构造函数:
// constructor for A
template < ..typename list >
A ( ... input iterators list... )
: G() //calls constructor for G
, EPred(...) //some constructor for predicate
, FG( boost::make_filtered_graph(G, EPred) ) //creates your filtered graph
{
// fill the graph G with some values passed in constructor argument list.
}
其余代码可以保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.