Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default copy move constructor efficiency different

if default copy constructor provider by compiler only make a shallow copy(copy the pointer of a member in heap to target object's corresponding member field), what is the difference between default copy constructor and default move constructor?

I think default move constructor should not be more more efficient than default copy constructor, as no deep copy happened. Am I right?

like image 574
Machi Avatar asked Apr 07 '26 17:04

Machi


1 Answers

what is the difference between default copy constructor and default move constructor?

A default copy constructor does memberwise copy of the data members while a default move constructor does memberwise move of the data members. That is, the default move constructor steal resources instead of copying them from the passed argument.

like image 84
Anoop Rana Avatar answered Apr 10 '26 06:04

Anoop Rana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!