What was the rationale for implementing links in C ++?

From a discussion that occurred in my recent question ( Why is a C ++ link considered safer than a pointer? ), This raises another question for me: what exactly was the rationale for implementing links in C ++?

+1
source share
5 answers

Section 3.7 Stroustrup The design and evolution of C ++ describes the introduction of language references. If you are interested in justifying any C ++ function, I highly recommend this book.

. , . , "", , , . 68.

C , , . , . , , . :

a = b - c;

( ) ,

a = &b - &c;

. , &b - &c C, .

, . , ++ , . Algol68 r1 = r2 r1 , r1 ( r1) r2. ++.

+11

(, " ?" )

std::auto_ptr::operator*() ? std::vector::operator[]?

+2

. , , , - ++ *. , . , - - , ( ) ..

, , .

, , ++, (), .

+2

, , - , , , . , , , . , .

"" - , ++ . ​​ , , . , -, . , - , , , .

0

Allow operator overload. They wanted operators to be overloaded for both objects and pointers, so they needed a way to refer to the object with something other than a pointer. Therefore, a link has been introduced. It is in the "Project and Evolution of C ++".

0
source

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


All Articles