面试题答案
一键面试class Vector2D {
public:
int x;
int y;
Vector2D(int a = 0, int b = 0) : x(a), y(b) {}
// 重载二元运算符 '+'
Vector2D operator+(const Vector2D& other) const {
return Vector2D(x + other.x, y + other.y);
}
};
class Vector2D {
public:
int x;
int y;
Vector2D(int a = 0, int b = 0) : x(a), y(b) {}
// 重载二元运算符 '+'
Vector2D operator+(const Vector2D& other) const {
return Vector2D(x + other.x, y + other.y);
}
};