无法编译boost heap d_ary_heap

时间:2014-05-30 04:46:10

标签: c++ boost

我是新手来提升。我正在尝试使用d_ary_heap。以下是程序片段:

#include "boost/heap/d_ary_heap.hpp"

#include "boost/heap/priority_queue.hpp"

using namespace boost;

class c {

public:
    c(size_t count) : _count(count) {}
    size_t count() const { return _count; }
    bool operator < (const c& rhs) const { return count() < rhs.count(); }
    bool operator == (const c& rhs) const { return count() == rhs.count(); }


private:
  size_t _count;

};

int main()
{
  heap::d_ary_heap<c, heap::arity<2>> pq;
  //heap::priority_queue<c> pq;  // This works

  c s1(10);
  pq.push(s1);

  c s2(20);
  pq.push(s2);

  assert(pq.top() == s2);
  return 0;
}

我收到以下错误:

queue.cc: In function 'int main()':
queue.cc:24:44: error: 'pq' was not declared in this scope
queue.cc:24:44: error: template argument 1 is invalid
queue.cc:24:34: error: template argument 2 is invalid

感谢任何帮助。 .................................................. ..........................................

1 个答案:

答案 0 :(得分:2)

包括heap :: arity&lt; 2&gt;之后包含空格:

heap::d_ary_heap<c, heap::arity<2> > pq;

编译器对待&gt;&gt;作为运算符而不是 d_ary_heap

的模板声明的一部分