这行是什么意思?我们可以为属性以外的对象分配一些东西吗?

发布于 2025-01-14 20:34:57 字数 1585 浏览 2 评论 0 原文

您好,这是我的第一个问题。

我对 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

Greetings this is my first question here.

I'm really new to C++, and to Object Oriented Programming as well.

So, my tasks currently need to wrap this C++ library, the code is:

#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);
}

So, what I don't understand is the last line. The basic C++ OOP that I understand is that we can create an object and can assign an attribute to it:

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";

But, what I don't understand in the last line (from the library) is it's creating an object from a class which is results but after that, directly assign to something:

results = cavc::parallelOffset(input, 3.0);

This is the header file:

https://github.com/jbuckmccready/CavalierContours/blob/master/include/cavc/polylineoffset.hpp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2025-01-21 20:34:57

该行正在调用名为 parallelOffset 的函数,该函数是在名为 cavc 的命名空间中声明的。该函数返回 std::vector> 类型的对象,因此该行声明该类型的对象并将其设置为等于函数返回的值。

语法与例如相同

float x = sin(3.0);

...只是具有更复杂的返回类型(std::vector>,又名 cavc 向量: :Polyline 对象)

std::vector<cavc::Polyline<double>> results = cavc::parallelOffset(input, 3.0);

The line in question is calling a function named parallelOffset, that was declared in a namespace called cavc. The function returns an object of type std::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.

float x = sin(3.0);

... just with a more complicated return-type (std::vector<cavc::Polyline<double>>, a.k.a a vector of cavc::Polyline<double> objects)

std::vector<cavc::Polyline<double>> results = cavc::parallelOffset(input, 3.0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文