Cpp oops - copy constructor

didn’t understand copy constructor logic explained between 5th to 6th minute

Hello @Divya_321,

Try to relate what sir has explained in the video with the following:

If an object is passed as value to the Copy Constructor then its copy constructor would call itself, to copy the actual parameter to the formal parameter.
Explanation:
When you would write:
Car F = C;
The copy constructor will be invoked/called and C will be passed as the parameter.
When you pass any parameter by value, it’s copy is created and that copy would be excepted by the called function.
But, in this program the parameter passed is an object of the class i.e. C.
So, when the compiler will implicitly create it’s copy, it will call the copy constructor.
Again the entire process will repeat for this call… leading to another.
Hence, an endless chain of call to the copy constructor will be initiated. This process would go on until the system run out of memory.

Hence, in a copy constructor, the parameter should always be passed as reference.
In pass by reference, no copy of parameter is created.

Hope, this would help.
Give a like if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.