Copy constructor

why do we need to put & in copy constructor?

hi @aggarwal.naman21,
its passed by reference Because if it’s not by reference, it’s by value. To do that you make a copy, and to do that you call the copy constructor. But to do that, we need to make a new value, so we call the copy constructor, and so on…

(You would have infinite recursion because “to make a copy, you need to make a copy”.)

1 Like

ohk so by passing by reference makes the compiler understand that there is a copy so it doesn’t calls the copy constructor again ?

1 Like

@aggarwal.naman21, yup wen u pass by reference it doesnt make any copy

1 Like