“二进制表达式的无效操作数”当使用 Boost.Geometry 时?
当我尝试增强几何差异函数时,我收到一个很长的编译器错误,而具有相同接口和可能相关实现工作的并集和交集:
bg::unique_(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::intersection(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::difference(OldPolygon, Node->Polygon, NodePolygon); // dies
第一个错误是:
boost/range/size.hpp:32:13: error: invalid operands to
binary expression ('
boost::reverse_iterator<
__gnu_cxx::__normal_iterator<
const GraphPoint *,
std::vector<
GraphPoint,
std::allocator<GraphPoint>
>
>
>' and 'int')
BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
似乎由于某种原因,迭代器差异返回反向迭代器而不是距离。 ..
类型声明为:
namespace bg = boost::geometry;
struct GraphPoint
{
int x, y;
GraphPoint(int x, int y) : x(x), y(y) { }
GraphPoint() : x(0), y(0) { }
GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }
bool operator ==(const GraphPoint &other) const
{
return x == other.x && y == other.y;
}
};
BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)
typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;
MultiPolygon OldPolygon;
struct Node
{
Polygon Polygon;
}
MultiPolygon NodePolygon;
完整的错误位于此处,以防有人喜欢挖掘。
我怎样才能编译这个?
I get a long compiler error when I try boost geometry difference function, while the union and intersection that have same interface and probably related implementation work:
bg::unique_(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::intersection(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::difference(OldPolygon, Node->Polygon, NodePolygon); // dies
The first error is:
boost/range/size.hpp:32:13: error: invalid operands to
binary expression ('
boost::reverse_iterator<
__gnu_cxx::__normal_iterator<
const GraphPoint *,
std::vector<
GraphPoint,
std::allocator<GraphPoint>
>
>
>' and 'int')
BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It seems for some reason the iterator difference is returning reverse iterator instead of distance...
The types are declared as:
namespace bg = boost::geometry;
struct GraphPoint
{
int x, y;
GraphPoint(int x, int y) : x(x), y(y) { }
GraphPoint() : x(0), y(0) { }
GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }
bool operator ==(const GraphPoint &other) const
{
return x == other.x && y == other.y;
}
};
BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)
typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;
MultiPolygon OldPolygon;
struct Node
{
Polygon Polygon;
}
MultiPolygon NodePolygon;
The full error is in here incase anyone likes to dig.
How can I make this compile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我根据您的示例成功编译了一个示例:
我必须修改 Node 结构,这是生成的代码:
我收到两个警告(
警告 C4244:'=':从 'double' 到 'int' 的转换,可能会丢失数据
)但它可以编译。I successfully compiled an example based on your example with:
I had to modify the Node structure, this is the resulting code:
I get two warnings (
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
) but it compiles.