Classify and use the same name?

advertisements

I'm quite new to C++ and OOP so I'm particularly interested about one aspect. Moment when I define new class. I give it name without any functions in it. But outside of class there's function with the data type of class name.

I'm wondering about this particular example:

class point
{
public:
    double x;
    double y;
};

point solve(line v1, line v2);

int main()
{
    point A = solve(_a, _b);
}

point solve(line v1, line v2)
{
    point a;

    a.x = 0;
    a.y = 0;

    //more code here

    return a;
}

I don't really get it how can a class name become an independent function with data type of that class and functions name to be different (point solve()). It's not a constructor, not a reference as it returns value. Inside that function there's another data type Point.

Is there a way how to write it more understandable for a beginner?


Well, find a good C++ book first. Perhaps C++ Primer.

I guess you are asking

point solve(line v1, line v2)

point is the type of returning value. So this reads like: solve is a function accepting two parameters, both parameters have type line, and return one value with type point.