January 2019
Intermediate to advanced
512 pages
14h 5m
English
The second most common type of ownership is exclusive ownership—the code creates an object and will delete it later. The task of deletion will not be delegated to someone else, as neither an extension of the lifetime or the object is permitted. This type of memory ownership is so common that we do it all the time without even thinking about it:
void Work() { Widget w; Transmogrify(w); Draw(w);}
All local (stack) variables express unique memory ownership! Note that ownership in this context does not mean that someone else will not modify the object. It merely means that when the creator of the w widget—the DoWork() function, in our case—decides to delete it; the deletion will succeed (nobody has deleted it already) ...