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; }



LinkBack URL
About LinkBacks
perator+(point) with objects of type point1 ?


