Here I understand rhs means right hand side but I don't understand how does compiler understand "rhs" refers to right hand side. And can someone explain in which case will this overloading be necessary?
MyArray<T>& operator=(const MyArray<T>& rhs);
What is the difference between SAS and RHS? In SAS rule, we consider the angle between two sides that we are equal, but in RHS, the placement of angle does not matter as we take hypotenuse and any one of the other two corresponding sides.
The test is therefore given the initials RHS for 'Right angle', 'Hypotenuse, 'Side'. RHS congruence test. The hypotenuse and one side of one right-angled triangle are respectively equal to the hypotenuse and one other side of another right-angled triangle then the two triangles are congruent.
Ans: By RHS criteria, two right-angled triangles are said to be congruent if the hypotenuse and one side of one triangle are equal to the hypotenuse and corresponding side of the other triangle.
The compiler doesn't know that rhs
stands for "right hand side", and in fact the name of that variable can be anything you like.
The compiler "knows" how to format this because the syntax of operator=
requires it to be this way.
class A
{
public:
A& operator=(const A& other);
};
The language defines the usage of this operator to take the form:
A a, b;
a = b;
The code above calls A::operator=(const &other)
against the instance of A
named a
, and uses the instance of A
named b
as other
.
The standard assignment operator to an instance of the same type has the prototype
MyArray<T>& operator=(const MyArray<T>&);
The name rhs
is normally given to the function parameter since it appears on the right hand side of an assignment when the operator is invoked. It improves the legibility of your source code, that's all.
rhs
is just a name people usually use for that operator, it has no special meaning. The way that operator is defined always makes the argument the right-hand element.
If you do something like:
int a = 5;
int b = 3;
a = b;
The assignment part is actually just a function call:
a.operator=(b);
Nothing special going on. The parameter name doesn't matter, just the signature which consists of the return type and parameters types, not names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With