这个问题是关于Boost Graph Library
的。
假设我的图表类型定义如下:
using Graph = boost::adjacency_list<vecS, setS, directedS, State>;
现在,如果我理解正确的话,我可以向图中添加一个新的 State
对象 s
,如下所示:
auto vd = add_vertex(g); // g is a Graph object
g[vd] = s;
这种方式有两个问题:
它要求
State
有一个默认构造函数。对于这个特定的类State
来说,默认构造函数根本没有意义。这样,我就可以在添加顶点时支付
State
对象的默认构造费用。该成本是纯粹的运行时开销。
那么,有没有办法避免捆绑对象需要默认构造函数?
最佳答案
The types of all property values must be Copy Constructible, Assignable, and Default Constructible. The property maps obtained from the adjacency_list class are models of the Lvalue Property Map concept. If the adjacency_list is const, then the property map is constant, otherwise the property map is mutable.
您应该创建一个能够保存或引用您的状态
的属性类型。
对于第一步,您可能会成功使用采用该属性的重载:
auto vd = add_vertex(s, g); // g is a MutablePropertyGraph object
g[vd] = s;
查看其他docs
关于c++ - BGL : bundled object without a default constructor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810464/