我试图弄清楚它how boost::geometry
的for_each_segment
工作原理。文档告诉我,它for_each_segment
需要一个几何图形和一个仿函数。在我的示例中调用了这个函子polylength_helper
,只要这个片段没有编译,我就在那里增加一个数字以保持简单,直到它编译。
// foo.h
typedef boost::geometry::model::point<double, 2, bg::cs::cartesian> GeographicPoint;
typedef boost::geometry::model::linestring<GeographicPoint> GeographicPolyLine;
typedef boost::geometry::model::segment<GeographicPoint> GeographicSegment;
double poly_length(const GeographicPolyLine&);
template<typename Segment>
struct polylength_helper{
polylength_helper() : length(0){};
inline void operator()(Segment s){
length += 1;
};
double length;
};
// foo.cpp
double poly_length(GeographicPolyLine &poly){
polylength_helper<GeographicSegment> helper;
bg::for_each_segment(poly, helper);
return helper.length;
}
好吧,这不会编译。我使用clang
了一个更易于理解的输出,它说:
note: candidate function not viable: no known
conversion from 'model::referring_segment<point_type>' to
'boost::geometry::model::segment<boost::geometry::model::point<double, 2,
boost::geometry::cs::cartesian> >' for 1st argument
inline void operator()(Segment s){
^
谁能帮我吗?特别是我不知道referring_segment
消息中的来自哪里。
这是文档中的一个示例:
但我无法弄清楚这与我的版本有何不同,除了typedef
s.