Рет қаралды 11,959
Define your own deleter.
The smart pointer type unique_ptr is NOT just for automating deletes of heap-allocated pointers. By specifying a custom deleter type, you can use them to clean up any resource that doesn't clean up after itself. Yes, you can delete a new, but you can also free a malloc, fclose an fopen, or deallocate an allocate for a custom allocator type (feel free to use a stack allocator!). This can be useful for interoperating with C code or code from other languages, as well as to clean up after classes or incidental data structures that don't otherwise clean up after themselves.
― mCoding with James Murphy (mcoding.io)
Source code: github.com/mCodingLLC/VideosS...
unique_ptr intro video: • unique_ptr: C++'s simp...
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
/ mcoding
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
www.paypal.com/donate/?hosted...
Want to donate crypto? Check out the rest of my supported donations on my website!
mcoding.io/donate
Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information, Pi
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding