An example:
// Pos
class Pos {
public:
float x, y;
Pos(float ax, float ay) : x(ax), y(ay) {};
...
};
// Point
class Point : public Pos {
public:
Point(float ax, float ay) : Pos(ax, ay) {};
...
};
// Vector
class Vector : public Pos {
public:
Vector(float ax, float ay) : Pos(ax, ay) {};
...
};
// globals
Point operator+(const Point& l, const Vector& r)
{
return Point(l.x + r.x, l.y + r.y);
}
Vector operator+(const Vector& l, const Vector& r)
{
return Vector(l.x + r.x, l.y + r.y);
}
// also << and >>
...
A sample ROOT session (with classes been compiled into a shared library):
> Point p1, p2;
> Vector v1, v2;
> cout << v1 + v2 << endl; // ok
> 0 0 0
> cout << p1 + v1 << endl; // also ok
> 0 0 0
> cout << (p1 + p2) << endl; // emm ?
> 0 0 0
The last + seems strange for me (there’s no operator +(Point&, Point&)). Is it a feature ?