overload
e.g.1
#include <iostream> class Base2d { int x,y; public: Base2d():x(0),y(0){} Base2d(int _x, int _y):x(_x), y(_y){} int GetX() const { return x; } void SetX(int d) { x=d; } int GetY() const { return y; } void SetY(int d) { y=d; } }; Base2d operator+(const Base2d& a, const Base2d& b) { Base2d temp(a.GetX()+b.GetX(), a.GetY()+b.GetY()); return temp; } Base2d operator-(const Base2d& a, const Base2d& b) { Base2d temp(a.GetX()-b.GetX(), a.GetY()-b.GetY()); return temp; } Base2d operator*(const Base2d& a, const Base2d& b) { Base2d temp(a.GetX()*b.GetX(), a.GetY()*b.GetY()); return temp; } Base2d operator/(const Base2d& a, const Base2d& b) { Base2d temp(a.GetX()/b.GetX(), a.GetY()/b.GetY()); return temp; } int main(void) { Base2d plane1(10, 20), plane2(30, 40); Base2d plane=plane1+plane2; std::cout << "operator+" << std::endl; std::cout << plane.GetX() << std::endl; std::cout << plane.GetY() << std::endl; plane=plane1-plane2; std::cout << "operator-" << std::endl; std::cout << plane.GetX() << std::endl; std::cout << plane.GetY() << std::endl; plane=plane1*plane2; std::cout << "operator*" << std::endl; std::cout << plane.GetX() << std::endl; std::cout << plane.GetY() << std::endl; plane=plane1/plane2; std::cout << "operator/" << std::endl; std::cout << plane.GetX() << std::endl; std::cout << plane.GetY() << std::endl; return 0; }