c++ - 使用 Boost 图形库:boost::mutable_queue 中的 property_map

标签 c++ boost

我正在尝试实例化 boost::mutable_queue 的简单版本自定义 Node我定义的类型。我可以毫不费力地实例化 mutable_queue<double>使用以下代码片段的实例(使用 std 和 boost 命名空间,以及所有需要的包括):

int N = 100;

mutable_queue<double> *q = 
    new mutable_queue<double>(N, less<double>(), identity_property_map());

但是,当我尝试切换 double 时至 Node (为此我重载了 operator<operator== ),我再也无法让它工作了。这是我正在尝试的一个代表性示例:

typedef Node entry_t;
typedef vector<entry_t> storage_t;
typedef less<entry_t> comp_t;
typedef identity_property_map prop_map_t;
//typedef iterator_property_map<storage_t, 
//  property_map<storage_t, entry_t>::type >  prop_map_t;
typedef mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;

queue_t *q = new queue_t(N, comp_t(), prop_map_t());

这给了我这些方面的错误:

error: no matching function for call to ‘boost::mutable_queue >, std::less, boost::identity_property_map>::push(Node*&)’
    mutable_queue.h:100: note: candidates are: void boost::mutable_queue::push(const IndexedType&) [with IndexedType = UnitTest::Node_test()::entry_t, RandomAccessContainer = std::vector >, Comp = std::less, ID = boost::identity_property_map]

我怀疑我不明白如何使用 property_map .有人可以帮助我修复此代码段,并解释一下为什么这样做是正确的吗?

最佳答案

我没看到你在哪里调用推送,但看起来你在推送一个节点*,而你应该推送一个节点:

::push(Node*&)

它告诉你有一个 Node const& 的推送:

push(const IndexedType&)

其中 IndexedType = 节点

关于c++ - 使用 Boost 图形库:boost::mutable_queue 中的 property_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1269563/

相关文章:

c++ - 在编译器中运行,在线拒绝

c++ - 从模板分配空指针

c++ - 在 constexpr 函数中实例化多个模板

c++ - 使用 boost::asio 时的引用问题(我猜)

c++ - 查找所有在 Boost 中排序的

c++ - 创建自定义“字符串”(结构)拷贝

c++ - 派生类不从基类继承重载方法

c++ - 无法弄清楚为什么使用 boost 库的多精度计算对我不起作用

c++ - boost::asio::steady_timer() vs sleep() 我应该使用哪一个?

c++ - 如果您始终将其存储在 shared_ptr 中,您的接口(interface)是否需要虚拟析构函数?