嘗試從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相同的錯誤)。
啓發我喜歡你的解決方案比我的好,它使大量的清潔劑來訪問後臺的數據。 –