Write a program in C++, which demonstrate = operator overloading.
struct Point {
int x, y;
Point& operator=(const Point& p) noexcept {
x = p.x;
y = p.y;
}
};
int main() {
Point a, b;
a.x = 1;
a.y = 1;
b = a; // Point::operator=
return 0;
}
Comments
Leave a comment