4 ms·
It depends. The trick to using new correctly is to put it in a function whose sole purpose is to immediately store new's result in the smart handle. I.E. You'
by Suncho 12y ago
It depends. The trick to using new correctly is to put it in a function whose sole purpose is to immediately store new's result in the smart handle. I.E. You're writing a function that's analogous to the make_unique function.
You might need to do this if you're implementing your own smart handle or writing a factory function for a class with a private constructor (make_unique will not work).
Off the top of my head, I can't think of any good reasons to use delete.
- lomnakkus 12y agoIf your handles are pointer types, you should still use unique_ptr, you just need to give it a custom "deleter". (Of course you should probably still encapsulate this in a function like make_xxx() just to avoid the potential mistake of not supplying the correct deleter everywhere.)