2D point class in c++ code example

Example: 2D point class in c++

class point
{

private:
    float x;
    float y;

public:
    point(float a = 0, float b = 0)
    {
        x = a;
        y = b;
        cout << "***" << x << "," << y << endl;
    }
    point operator+(point p)
    {
        point p3;
        p3.x = this->x + p.x;
        p3.y = this->y + p.y;

        return p3;
    }
    friend point operator*(float a, point p)
    {
        return p * a;
    }

    point operator*(float a)
    {
        point p1;
        p1.x = a * x;
        p1.y = a * y;
        return p1;
    }

    void print()
    {
        cout << this->x << "\n"
             << this->y << "\n";
    }
    friend float get_x(point);
};
float get_x(point p)
{
    return p.x;
}

Tags:

Cpp Example