gpt4 book ai didi

c++ - BGL:没有默认构造函数的捆绑对象?

转载 作者:行者123 更新时间:2023-12-01 14:50:52 25 4
gpt4 key购买 nike

这个问题是关于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对象的默认构造付费。此成本是纯运行时开销。

  • 因此,有没有一种方法可以避免对 bundle 对象使用默认构造函数?

    最佳答案

    documentation:

    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.



    您应该使属性类型能够保存或引用 State

    对于第一步,您可能会成功实现带有属性的重载:
    auto vd = add_vertex(s, g); // g is a MutablePropertyGraph object
    g[vd] = s;

    查看其他 docs

    关于c++ - BGL:没有默认构造函数的捆绑对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810464/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com