Home > Net >  What does this line mean?, can we assign something to an object other than attribute?
What does this line mean?, can we assign something to an object other than attribute?

Time:03-17

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

CodePudding user response:

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);
  • Related