References in C ++

As soon as I read in a statement that

A language function that "closed a deal" to enable link operator overloading.

Why are links necessary to effectively support operator overloading? Any good explanation?

+3
source share
4 answers

Here is what Straustrup said in "Project and Evolution of C ++" (3.7 "links"):

Links were provided mainly to support operator overloading ....

C , , . , . , , . :

 a = b - c;

( ) ,

 a = &b - &c;

. , &b - &c C, .

+10

" → " . , , , . , - . , - .

, (, ).

: , , x @y ( "@" ) x.opertor@(y). , , - x , : , - , x+2 - x, , , . , () , , . x=y - , , , , .

, " " 90% , ...

+4

, , . , ; , .. , , ++, . , . ( , const ), .

+1

Usually, when you implement an operator, you want to work directly with the operand, and not with its copy, but when passing the pointer, you risk deleting the memory inside the operator. (Yes, it would be stupid, but nevertheless it would be a significant danger.) Links allow you to use a convenient way to access the pointer, not related to the "assignment of responsibility" that bears the passage of pointers.

0
source

Source: https://habr.com/ru/post/1739666/


All Articles