| |

VerySource

 Forgot password?
 Register
Search
Author: lfq372

Why must the formal parameters of the copy constructor be set to a reference type?

[Copy link]

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-2 16:45:01
| Show all posts
It's already very clear,
Value transfer requires calling the copy constructor, the original function itself is a copy constructor, infinite recursion
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 Hong Kong

Post time: 2020-8-2 17:15:01
| Show all posts
Is there only one reason for the infinite loop? Not right
Reply

Use magic Report

0

Threads

24

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-4 20:00:01
| Show all posts
Reply

Use magic Report

0

Threads

24

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-4 20:15:01
| Show all posts
This is an old question, I have seen it at least n times.

-------------------------------------------------- ----------------------------------
If it is not a reference,
Then the parameter itself needs to copy an object,
The copy of the object needs to call the copy structure,
The parameter of the copy construction is an object again, and the copy construction is called again...

Endless loop. . .

-------------------------------------------------- ----------------------------------
correct.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 22:00:01
| Show all posts
Actually, I don’t really understand this question. Thanks, I learned it. Hey
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