gpt4 book ai didi

c++ - 用boost::polygon添加多边形无法编译?

转载 作者:行者123 更新时间:2023-12-02 10:14:10 30 4
gpt4 key购买 nike

可能这是一个愚蠢的问题,只是一个简单的问题,但是我无法编译相对简单的代码。我想做的是使用boost::polygon(一些伪代码显示相关部分)添加/连接两个多边形:

#include <boost/polygon/polygon.hpp>

boost::polygon::polygon_with_holes_data<int> baseData; // base data to work with
boost::polygon::polygon_with_holes_data<int> opData; // operational data to be applied to base

fill both baseData and opData via set() and set_holes() here...

boost::polygon::polygon_set_data<int> result=baseData + opData;
最后一行是我偶然发现的地方:编译器说多边形_with_holes_data的运算符“+”是未知的:
error C2678: binary '+' : no operator found which takes a left-hand operand of type 'boost::polygon::polygon_with_holes_data<T>' (or there is no acceptable conversion)
当我使用polygon_data而不是polygon_with_holes_data时,会出现相同的错误。知道我在做什么错吗?
谢谢!

最佳答案

我在文档中提到的唯一运算符位于polygon sets
另外,请注意:

Operators are declared inside the namespace boost::polygon::operators.


因此,请确保实际使用它们:
Live On Coliru
#include <boost/polygon/polygon.hpp>
#include <boost/polygon/polygon_set_data.hpp>
#include <boost/polygon/polygon_with_holes_data.hpp>

namespace bp = boost::polygon;
using poly = bp::polygon_with_holes_data<int>;
using pset = bp::polygon_set_data<int>;

int main() {
poly baseData; // base data to work with
poly opData; // operational data to be applied to base

// fill both baseData and opData via set() and set_holes() here...

using namespace bp::operators;
pset x = baseData + opData;
}

关于c++ - 用boost::polygon添加多边形无法编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62528083/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com