//operator Overloading//overriding rules need to satisfy the rules of the operator itself classCmypoint {intx, y; Public: Cmypoint (); Cmypoint (intXinty); ~Cmypoint (); Cmypointoperator+ (CmypointConst& PT)Const;//The value of this cannot be modifiedFriend Cmypointoperator-(CmypointConst&P1, CmypointConst&p2); Cmypoint&operator++();//front, because is self, so to add &Cmypointoperator++(int);//+ + post, int is the identifier is not used & is because, first assignment in the operation, assignment is to produce a temporary variable firstfriend Ostream&operator<< (ostream& OS, cmypointConst& PT);//friend because in the input output, the first parameter is not this, but the input output streamFriend istream&operator>> (istream& is, Cmypoint &PT); }; Cmypoint cmypoint::operator+ (CmypointConst& PT)Const{cmypoint temppt; Temppt.x= This->x +Pt.x; Temppt.y= This->y +Pt.y; returntemppt; } myvectoroperator-(Myvector I, Myvector j) {returnMyvector (i.x-j.x, i.y-j.y); } cmypoint& Cmypoint::operator++() { (* This). x + +; This->y++; return* This; } cmypoint Cmypoint::operator++(int) {Cmypoint temppt= * This; This->x++; This->y++; returntemppt; } ostream&operator<< (ostream& OS, cmypointConst&PT) {OS<< Pt.x <<'\ t'<< Pt.y <<Endl; returnOS; } IStream&operator>> (istream& is, Cmypoint &PT) { is>>Pt.x; is>>Pt.y; return is; } cmypointoperator-(CmypointConst& P1, CmypointConst&p2) {Cmypoint temppt; Temppt.x= p1.x-p2.x; Temppt.y= P1.y-p2.y; returntemppt; }
c++--class operator overloading