Feature?

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 ?

Andriy,

I can not reproduce this problem. As far as I tried, Cint
correctly complains there is no operator+ for class Point.
Is there some other situation?

Thank you
Masa Goto

Hi,

Did you try to compile the same code ? Do you have a constructor takes that a Point or a Pos or a Vector?

Cheers,
Philippe.

[quote=“pcanal”]Hi,

Did you try to compile the same code ? Do you have a constructor takes that a Point or a Pos or a Vector?

Cheers,
Philippe.[/quote]

Thank you for pointing this out.

Indeed, in Point and Vector I had non-explicit constructors taking const Pos&, so the Point1+Point2 was actually Point1+Vector(Point2). Declaring them as explicit helped.