尝试从r-tree中删除值时出现编译错误。我还将一个原始指针与框一起存储,这似乎是导致问题 - 如果我存储int,字符串或shared_ptr,则不会收到错误。在boost R树中存储原始指针的问题
我没有选择切换到shared_ptr,因为所有这些来自遗留库。是否有另一种解决方法?
我有树的定义如下:
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
namespace bgm = boost::geometry::model;
typedef boost::geometry::model::point<float, 2, bg::cs::cartesian> point_t;
typedef boost::geometry::model::box<point_t> box_t;
typedef std::pair<box_t, Data*> value_t;
boost::geometry::index::rtree<value_t, boost::geometry::index::quadratic<16>> rtree;
而失败的代码如下:
while(!rtree.empty()) {
auto it = rtree.begin();
auto value = *it;
rtree.remove(value); // <-- this is where the error appears.
}
而且错误如下:
...../boost/geometry/index/equal_to.hpp:127:60: error: ambiguous class template instantiation for 'struct boost::geometry::index::detail::equals<NdsInstance*, void>'
&& detail::equals<T2>::apply(l.second, r.second);
^
...../boost/geometry/index/equal_to.hpp:28:8: error: candidates are: struct boost::geometry::index::detail::equals<Geometry*, Tag>
struct equals<Geometry *, Tag>
^
...../boost/geometry/index/equal_to.hpp:37:8: error: struct boost::geometry::index::detail::equals<T, void>
struct equals<T, void>
^
...../boost/geometry/index/equal_to.hpp:127:60: error: incomplete type 'boost::geometry::index::detail::equals<NdsInstance*, void>' used in nested name specifier
&& detail::equals<T2>::apply(l.second, r.second);
^
全部代码示例可在Colliru上找到。我正在使用gcc 4.9.3和boost 1.62(与boost 1.61相同的错误)。
启发我喜欢你的解决方案比我的好,它使大量的清洁剂来访问后台的数据。 –