Skip to the content.

Transferring Ownership

Back to Homepage
Back to Week 3


Smart Pointers

class List {
  unique_ptr<int[]>backingArray;
}

Copy

Move

RegistrationForm -> unique_ptr(Person) createPerson() -> return unique_ptr(new Person())

// Because person will outlive form, maybe return pointer as person will be on heap
// Dont want to tie their lifetimes together

make_unique<Person>(...); // Creates a new person without using new keyword