这行是什么意思?我们可以为属性以外的对象分配一些东西吗?
您好,这是我的第一个问题。
我对 C++ 和面向对象编程都很陌生。
所以,我的任务当前需要包装这个C++库,代码是:
#include "cavc/polylineoffset.hpp"
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
// input polyline
cavc::Polyline<double> input;
// add vertexes as (x, y, bulge)
input.addVertex(0, 25, 1);
input.addVertex(0, 0, 0);
input.addVertex(2, 0, 1);
input.addVertex(10, 0, -0.5);
input.addVertex(8, 9, 0.374794619217547);
input.addVertex(21, 0, 0);
input.addVertex(23, 0, 1);
input.addVertex(32, 0, -0.5);
input.addVertex(28, 0, 0.5);
input.addVertex(39, 21, 0);
input.addVertex(28, 12, 0);
input.isClosed() = true;
// below this is the line that i dont understand
std::vector<cavc::Polyline<double>> results = cavc::parallelOffset(input, 3.0);
}
所以,我不明白的是最后一行。我理解的基本 C++ OOP 是我们可以创建一个对象并为其分配一个属性:
class MyClass { // The class
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};
myClass myObject;
myObject.myNum = 1;
myObject.myString = "something";
但是,我在最后一行(来自库)中不明白的是它是从一个类创建一个对象,该类是 < code>results 但之后,直接分配给某些东西:
results = cavc::parallelOffset(input, 3.0);
这是头文件:
https://github.com/jbuckmccready/CavalierContours/blob/master/包括/cavc/polylineoffset.hpp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该行正在调用名为
parallelOffset
的函数,该函数是在名为cavc
的命名空间中声明的。该函数返回std::vector>
类型的对象,因此该行声明该类型的对象并将其设置为等于函数返回的值。语法与例如相同
...只是具有更复杂的返回类型(std::vector>,又名 cavc 向量: :Polyline 对象)
The line in question is calling a function named
parallelOffset
, that was declared in a namespace calledcavc
. The function returns an object of typestd::vector<cavc::Polyline<double>>
, so the line is declaring an object of that type and setting it equal to the value retuned by the function.The syntax is the same as e.g.
... just with a more complicated return-type (
std::vector<cavc::Polyline<double>>
, a.k.a a vector ofcavc::Polyline<double>
objects)