The assignment operator should assign one object to the value of another. The assigned object should be returned by reference. It must be defined as a member function.
struct point {
int x, y;
// copy assignment, user-defined
point& operator=(const point& other) {
this->x = other.x;
this->y = other.y;
return *this;
}
// move assignment, explicitly defaulted
point& operator=(point&&) = default;
};
Note: the copy assignment operator can accept other
by value too.
<:cppreference:875716540929015908>
Copy Assignment Operator
<:cppreference:875716540929015908>
Move Assignment Operator
?creditFooter 162964325823283200