【发布时间】:2014-06-09 01:13:20
【问题描述】:
考虑一个简单的例子:
#include <boost/heap/fibonacci_heap.hpp>
class MyClass;
struct compare_distances
{
bool operator()(const MyClass* n1, const MyClass* n2) const
{
return n1->distance > n2->distance;
}
};
typedef boost::heap::fibonacci_heap<MyClass*, boost::heap::compare<compare_distances> > fib_heap;
class MyClass
{
public:
string name;
double distance;
fib_heap::handle_type handle;
};
我想以这种方式访问堆中 MyClass 对象的句柄。所以我转发声明 MyClass。但是编译器说:
错误:无效使用不完整类型“const class MyClass”(compare_distances 中的return 行错误)。
如何解决?
有必要实现一个方便的对象网络,例如:
class MyClass
{
public:
string name;
double distance;
fib_heap::handle_type handle[4]; // handles for other objects of MyClass
};
【问题讨论】:
标签: c++ boost heap handle fibonacci-heap