我试图遍历boost多边形中的点以对它们执行操作。要显示我的问题的简化版本:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon;
int main()
{
polygon polygonTest;
boost::geometry::read_wkt("POLYGON((-2 2, 2 2, 2 -2, -2 -2, -2 2))", polygonTest);
for (point_type point : boost::geometry::exterior_ring(polygonTest))
{
double xCoord = point.x;
}
return 0;
}
我收到以下错误:
'boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>::x': function call missing argument list; use '&boost::geometry::model::d2::point_xy<double,boost::geometry::cs::cartesian>::x' to create a pointer to member
我忽略了解决这个问题的方法?
答案 0 :(得分:1)
您正在使用成员函数 x
。但是你忘了叫它:
double xCoord = point.x();
请参阅下面的工作样本
问。我在忽视什么
您忽略了错误消息中的信息。
GCC:error: cannot resolve overloaded function ‘x’ based on conversion to type ‘double’
它告诉你,你要将一个函数x
分配给一个双...
Clang:error: reference to non-static member function must be called; did you mean to call it with no arguments?
它甚至会列出您可能需要的重载
<强> Live On Coliru 强>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon;
int main() {
polygon polygonTest;
boost::geometry::read_wkt("POLYGON((-2 2, 2 2, 2 -2, -2 -2, -2 2))", polygonTest);
for (point_type point : boost::geometry::exterior_ring(polygonTest)) {
double xCoord = point.x();
}
}