【发布时间】:2012-09-19 12:31:33
【问题描述】:
使用fibonacci_heap 会导致编译错误:
struct Less: public binary_function<Node*, Node*, bool>
{
bool operator()(const Node*& __x, Node*& __y) const
{ return __x->time < __y->time; }
};
boost::fibonacci_heap<Node*, Less >* m_heap;
然后
Less* ls = new Less;
m_heap = new boost::fibonacci_heap<Node*, Less >(1000, (*ls));
任何运行m_heap->push(n) 的尝试都会导致
no match for call to ‘(TimeSync::Less) (TimeSync::Node* const&, TimeSync::Node*&)’
UnmanagedUtils/Trading/Simulation/TimeSync.h:50: note: candidates are: bool TimeSync::Less::operator()(const TimeSync::Node*&, TimeSync::Node*&) const
/usr/local/include/boost-1_35/boost/property_map.hpp: In function ‘Reference boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::identity_property_map, Reference = unsigned int, K = TimeSync::Node*]’:
【问题讨论】:
-
你用记忆做奇怪的事情有什么原因吗?即在没有明显原因的情况下在堆上分配数据。
-
我需要Less对象在这个函数的作用域之后还活着,但是不管怎样,将Less声明为局部变量结果相同
-
另外,调用所期望的方法的方法签名表明 const 修饰符不在正确的位置。尝试将您的签名更改为:
bool operator()(Node* const& __x, Node*& __y) const -
如果你需要它存活的唯一原因是堆可以继续拥有它,它已经拥有它,因为你传递了一个副本。
-
以前做过:),没有帮助,不是这里的问题(关于 const 限定符)