boost :: fibonacci_heap:带有比较器重新定义圆形定义错误的嵌套定义
boost::fibonacci_heap: Nested define of handle with comparator redefined circular definition errors
提升文档和以前的堆栈溢出都提供了如何定义自定义比较函数的工作示例,并在boost堆的节点类型中包含句柄。但是,当我将这两个功能(自定义定义比较函数和节点类型中的句柄(结合起来时,我会发现错误报告不完整类型的" struct compare_node"。
https://www.boost.org/doc/libs/1_63_0/doc/html/heap/heap/concepts.html#heap.concepts.mutability
使用boost fibonacci_heap
定义比较fibonacci堆的功能
减少斐波那契堆中的操作,boost
除了预先定义节点的两个结构和compare_node之外,我不确定要解决圆形性,同时仍将手柄固定为节点结构中的成员。
#include <boost/heap/fibonacci_heap.hpp>
struct compare_Node; //predefine to avoid circular issues
struct Node; //predefine to avoid circular issues
using fib_heap = boost::heap::fibonacci_heap<struct Node*,
boost::heap::compare<struct compare_Node>>;
// 6-byte struct total
struct Node {
double value;
fib_heap::handle_type* handle; // orig
};
// override for min_heap
struct compare_Node
{
bool operator() (struct Node* const n1, struct Node* const n2) const
{
return n1->value > n2->value;
}
};
int main() {
fib_heap heap;
return 0;
}
仅在operator()
的声明中定义compare_Node
。指向Node
的指针不需要Node
定义。Node
定义后,您可以添加operator()
的主体:
struct compare_Node
{
bool operator() (struct Node* const n1, struct Node* const n2) const;
};
using fib_heap = boost::heap::fibonacci_heap<struct Node*,
boost::heap::compare<struct compare_Node>>;
// 6-byte struct total
struct Node {
double value;
fib_heap::handle_type* handle; // orig
};
bool compare_Node::operator() (struct Node* const n1, struct Node* const n2) const
{
return n1->value > n2->value;
}
在线演示。
相关文章:
- 使用命名空间时出现多个定义错误
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在头文件和 cpp 文件中使用一次 #pragma 时出现结构重定义错误
- 链接阶段出现多重定义错误
- 避免模板类中的重定义错误
- 即使我没有包含多个文件,C++中的多个定义错误
- 跨多个类的全局变量而不会出现重定义错误?
- 尝试运行 wasm 函数时出现模块未定义错误
- C++ 预期的左大括号以及重定义错误
- C++:成员的越界声明必须是纯虚函数的定义错误
- c++中数组的未定义错误
- Visual C:模板类中的自定义错误消息
- 为什么C++模板不会导致多个定义错误?
- 只有一个定义/声明时标头声明变量的多堆定义错误
- C++ 在多个其他类中使用单个类 - 编译时出现多个定义错误
- 基类未定义.错误 C2504
- Q 斯坦达项重定义错误
- 可视化C++中的结构定义错误
- VC++ C2011 重定义错误 - 未使用的头文件