January 2018
Intermediate to advanced
374 pages
9h 53m
English
In this section, we will dig into the details of using new and delete. We are all familiar with the standard way of using new for creating an object on the free store and then deleting it using delete:
auto user = new User{"John"}; // allocate and construct
user->print_name(); // use object
delete user; // destruct and deallocate
As the comments suggest, new actually does two things:
The same thing goes with delete: