1. ## operator overloaeded inheritance

Every book says that if you overload an operator(but =) in base class , you could use it in any derived class.

How do I use the point:perator+(point) with objects of type point1 ?

Code:
```#include <cstdlib>
#include <iostream>

using namespace std;

class point
{
int  x,y;
public:
point(void)
{
}
point(int Ix, int Iy)
{
x = Ix;
y = Iy;
}
void show(void) const
{
cout << "x = " << x << " y = " << y << endl;
}
point operator+(point p)
{
point  ret;

ret.x = x + p.x;
ret.y = y + p.y;
return(ret);
}
};

class point1 : public point
{
public:
point1(void):point()
{
}
point1(int Ix, int Iy):point(Ix,Iy)
{
}
point1(point &pin)
{
(*this) = (point1)pin;
}
point1 operator+(point1 p)
{
point pcur = (point)(*this);
point pon = (point)p;
point pans = pcur+pon;
// Until this line everthing is good
// then he says
// "no matching function for call to `point1::point1(point&)'
//
// so I tried point1::point1(point &pin)
// and everthing crashes !!!
return( (point1)(pans));
}

};

int main(void)
{
point1  p1(2,3);
point1  p2(18, 47);
point1  p3;

p3 = p1+p2;
p3.show();

system("PAUSE");
return EXIT_SUCCESS;
}```

2. If I'm understanding you right, you want to be able to call point::operator+() from within point1::operator+(). The way to do it would be (using your declarations);
Code:
```point1 point1::operator+(point1 p)
{
point1 temp;
temp.point::operator+((point)p);
//   other stuff specific to point1 addition
return temp;
}```
I also suggest eliminating the constructor of point1 that accepts a point as an argument.

Incidentally, I suggest you would often be better off passing arguments of type point or point1 via const reference to operator+(), and to make the operators const, viz;

Code:
```class point
{
// other stuff eliminated for brevity sake
public:
point operator+(const point &p) const;
{
point  ret;

ret.x = x + p.x;
ret.y = y + p.y;
return(ret);
}
};

class point1 : public point
{
public:
point1 operator+(const point1 &p) const
{
point1 pcur(*this);
pcur.point::operator+(p);   // or pcur.point::operator+((const point &)p);
// other stuff specific to point1 addition
return pcur;
}

};```
One advantage of this is that a reference to a derived class can be implicity converted to a reference to an (unambiguous) base, meaning you don't need to do the explicit casting or worry about temporaries that the compiler might introduce.

3. ## Yes, but not What I wanted.

Originally Posted by grumpy
Code:
```class point1 : public point
{
public:
point1 operator+(const point1 &p) const
{
point1 pcur(*this);
pcur.point::operator+(p);   // or pcur.point::operator+((const point &)p);
// other stuff specific to point1 addition
return pcur;
}

};```
I wanted for point1:perator+ to behave just like point:perator+.
This is not what your point1:perator does, because you return pcur, which operate on the +.
For example :
Code:
```point1  p1(2,3), p2(8,7), p3;
p3 = p1+p2;```
I would like p3.x = 10 and p3.y = 10.
Your code does p3.x = 2 and p3.y = 3 which is p1 !

4. The problem is with your constructor point1(point).... the point of making the constructor is to tell the compiler how to construct/convert a base object to a derived, and you try to tell it to do it by casting creating an endless loops because it will use the constructor since no cast operator is defined

I corrected the constructor and removed your derived operator+ and it works now as expected
Code:
```#include <cstdlib>
#include <iostream>

using namespace std;

class point
{
int  x,y;
public:
point(void)
{
}
point(int Ix, int Iy)
{
x = Ix;
y = Iy;
}
void show(void) const
{
cout << "x = " << x << " y = " << y << endl;
}
point operator+(point p)
{
point  ret;

ret.x = x + p.x;
ret.y = y + p.y;
return(ret);
}
};

class point1 : public point
{
public:
point1(void):point()
{
}
point1(int Ix, int Iy):point(Ix,Iy)
{
}
point1(point &pin):point(pin)
{
}

};

int main(void)
{
point1  p1(2,3);
point1  p2(18, 47);
point1  p3;

p3 = p1+p2;
p3.show();

system("PAUSE");
return EXIT_SUCCESS;
}```