Say, I've got a library which initializes an object like this:
Type *object;
lib_init(&object); // lib_init takes Type **object as the parameter
So, what if I want to use the library with my code which uses smart pointers? Is this a proper way?
Type *pObject;
lib_init(&pObject);
unique_ptr<Type> object(nullptr);
object.reset(pObject);
Or is there a smart way to do this?
lib_init? I would expect there to be a correspondinglib_destroyor something along these lines. It's unlikely thatdelete objectis the right way to dispose of an object allocated by a C language library - but that's whatunique_ptrwould do unless told otherwise.lib_disposeand I understand that there must be a custom deleter in order to call that function. Actually, the answer to my question is here stackoverflow.com/a/24543176/135749. Exactly the behavior that I was looking for. Thank you, everybody.