gpt4 book ai didi

c++ - 无法编译 boost 堆 d_ary_heap

转载 作者:行者123 更新时间:2023-11-28 02:47:30 27 4
gpt4 key购买 nike

我是新手。我正在尝试使用 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

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

最佳答案

在包含 heap::arity<2> 之后包含一个空格:

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

编译器将 >> 视为运算符,而不是 d_ary_heap 模板声明的一部分

关于c++ - 无法编译 boost 堆 d_ary_heap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23947211/

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