| |

VerySource

 Forgot password?
 Register
Search
View: 972|Reply: 6

Quote

[Copy link]

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-4 18:30:01
| Show all posts |Read mode
Some functions are written like this
istream&operator >> ();
What does&mean? Why is the return value a reference?
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 Unknown

Post time: 2020-5-18 13:30:01
| Show all posts
So that you can write
cout << "DDD" << "ddd" << endl;
Similar code
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 Hong Kong

Post time: 2020-5-21 08:30:01
| Show all posts
Efficient and save memory
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-22 12:00:01
| Show all posts
Handsome is one of the reasons.
The second is to refer to non-copying objects (that is, not copying functions), not all objects support copying.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 23:00:01
| Show all posts
The use of reference return values ​​can avoid generating a temporary object to receive the return value, which means that it avoids calling the copy constructor, reducing memory consumption, and it is very efficient, while achieving stream operations
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 23:15:01
| Show all posts
The return value of the function is a reference to the stream object
This can be used multiple times
I just want cout<<" "<<"a"<<endl;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 23:30:02
| Show all posts
Streams cannot be copied, so a reference must be returned.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list