C++: Difference between revisions

243 bytes added ,  21 October 2019
Line 113: Line 113:
After using <code>new</code> to allocate an object, use <code>delete</code> to deallocate it.  <br>
After using <code>new</code> to allocate an object, use <code>delete</code> to deallocate it.  <br>
You can also use C allocation with <code>malloc</code>, <code>calloc</code>, <code>alloca</code>, and <code>free</code>, though it is [https://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-and-or-new not recommended] since these are not type-safe.<br>
You can also use C allocation with <code>malloc</code>, <code>calloc</code>, <code>alloca</code>, and <code>free</code>, though it is [https://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-and-or-new not recommended] since these are not type-safe.<br>
====Custom Deleter====
[https://www.bfilipek.com/2016/04/custom-deleters-for-c-smart-pointers.html Custom Deleters]
When using smart pointers, the default deleter is the <code>delete</code> function but you can also specify your own deleter.


===Casting===
===Casting===