⚡ Build the skills to land top-paying quant jobs. Offer ends in 23d 14h 02m 20s23 days 14 hours 2 minutes 20 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 23d 14h 02m 20s23 days 14 hours 2 minutes 20 seconds.

Sign in to watch this lesson
Classes and Resource Ownership · 3:38
The default copy of a class copies its members one by one, so two Vectors end up sharing one heap block: a write through one shows up in the other, and at the end of the scope the block is deleted twice and the program aborts. We fix it with a copy constructor and a copy assignment that duplicate the block, allocate before deleting so a failure leaves the object untouched, and finish with the copy-and-swap idiom.