Operator overloading
Rust
impl Add for Point {
type Output = Point;
fn add(self, other: Point) -> Point {
Point { x: self.x + other.x, y: self.y + other.y }
}
}
Run
C++
Point& operator+ (const Point &other) {
this->x += other.x;
this->y += other.y;
return *this;
}
Run