![](/img/trans.png)
[英]How to use boost::geometry::distance with opencv cv::Point?
[英]Use lambda in the boost::geometry::for_each_point
我想將boost::model::polygon
轉換為boost::model::multi_point
,這是我的實現:
namespace bg = boost::geometry;
typedef bg::model::point<double, 3, bg::cs::cartesian> point3d;
bg::model::multi_point<point3d> result;
std::function<void(point3d)> appendPoint = [result](point3d point){
bg::append(result, point);
};
bg::for_each_point(polygon, appendPoint);
但是這段代碼給了我一個錯誤:
error: passing ‘boost::remove_reference<const boost::geometry::model::multi_point<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> > >::type {aka const boost::geometry::model::multi_point<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >}’ as ‘this’ argument of ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian>; _Alloc = std::allocator<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >; std::vector<_Tp, _Alloc>::value_type = boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian>]’ discards qualifiers [-fpermissive]
如果我理解正確,這種錯誤表明const正確性存在問題。 但我真的不知道,這段關於const
代碼有什么問題。 任何人都可以解釋我,我的錯誤在哪里,並且很熱門來解決它?
問題是bg::append
的第一個參數應該是對result
引用, result
是通過lambda中的值捕獲的。 將捕獲更改為
[&result](point3d point)
對於按值捕獲,它會報告有關const正確性的錯誤,因為您將臨時對象作為期望非const引用的參數傳遞。 如果是常量,則不會報告錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.