C++ &引用;二进制表达式“”的操作数无效;当使用Boost.Geometry时?

C++ &引用;二进制表达式“”的操作数无效;当使用Boost.Geometry时?,c++,boost,compiler-errors,boost-geometry,C++,Boost,Compiler Errors,Boost Geometry,当我尝试boost geometry difference函数时,我遇到了一个很长的编译器错误,而具有相同接口的并集和交集可能会执行相关的实现工作: bg::unique_(OldPolygon, Node->Polygon, NodePolygon); // compiles bg::intersection(OldPolygon, Node->Polygon, NodePolygon); // compiles bg::difference(OldPolygon, Node-&g

当我尝试boost geometry difference函数时,我遇到了一个很长的编译器错误,而具有相同接口的并集和交集可能会执行相关的实现工作:

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 &&
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boost/range/size.hpp:32:13:错误:到的操作数无效
二进制表达式('
反向迭代器<
__gnu_cxx::__normal_迭代器<
常量图形点*,
向量<
图形点,
分配器
>
>
>'和'int')
BOOST_断言((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;
namespace bg=boost::geometry;
结构图点
{
int x,y;
图形点(intx,inty):x(x),y(y){
图形点():x(0),y(0){}
图形点(常量图形点和其他):x(其他.x),y(其他.y){}
布尔运算符==(常量图形点和其他)常量
{
返回x==other.x&&y==other.y;
}
};
BOOST\u GEOMETRY\u REGISTER\u POINT\u 2D(图形点,int,bg::cs::笛卡尔坐标,x,y)
typedef bg::model::polygon polygon;
typedef多边形::环\ U型环;
typedef bg::model::multi_多边形MultiPolygon;
多多边形;
结构体类型
{
多边形;
}
多多边形节点多边形;
如果有人喜欢挖掘,则完全错误。

如何编译此示例?

我根据您的示例成功编译了一个示例,其中包括:

  • VS2005 SP1(Vista x64)
  • boost 1.48.0(刚刚下载)
我不得不修改节点结构,结果代码如下:

#include <boost/geometry/geometry.hpp> 
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp> // boost 1_48_0
//#include <boost/geometry/multi/geometries/multi_geometries.hpp> // if boost comes from SVN

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;
MultiPolygon NodePolygon;

struct Node
{
    Polygon p;
} node;

int main(int argc, char* argv[])
{
    bg::unique(OldPolygon); // only one parameter
    bg::intersection(OldPolygon, node.p, NodePolygon);
    bg::difference(OldPolygon, node.p, NodePolygon);

    return 0;
}
#包括
#包括
#包括
#包括
#包括//boost 1\u 48\u 0
//#包括//如果增压来自SVN
名称空间bg=boost::geometry;
结构图点
{
int x,y;
图形点(intx,inty):x(x),y(y){
图形点():x(0),y(0){}
图形点(常量图形点和其他):x(其他.x),y(其他.y){}
布尔运算符==(常量图形点和其他)常量
{
返回x==other.x&&y==other.y;
}
};
BOOST\u GEOMETRY\u REGISTER\u POINT\u 2D(图形点,int,bg::cs::笛卡尔坐标,x,y)
typedef bg::model::polygon polygon;
typedef多边形::环\ U型环;
typedef bg::model::multi_多边形MultiPolygon;
多多边形;
多多边形节点多边形;
结构体类型
{
多边形p;
}节点;
int main(int argc,char*argv[])
{
bg::unique(OldPolygon);//只有一个参数
bg::交集(OldPolygon、node.p、NodePolygon);
差异(OldPolygon、node.p、NodePolygon);
返回0;
}
我收到了两个警告(
警告C4244:“=”:从“double”转换为“int”,可能会丢失数据),但它可以编译