A library defines an opaque data type:
struct OpaqueStruct;
and the client code has to obtain and release an OpaqueStruct*
. I have access to the library source.
Unfortunately, neither shared_ptr
nor unique_ptr
cannot store that pointer giving an
error: invalid application of ‘sizeof’ to incomplete type.
The best thing I can think of is to borrow the finally guard from this post.
How do I use RAII for opaque struct pointers?
std::unique_ptr<T>
to create these entities in a context whereT
is undefined (the answer to the question StoryTeller pointed to does, though). – Charissastd::unique_ptr<OpaqueStruct, void(*)(OpaqueStruct*)> ops(newOpaqueStruct(), deleteOpaqueStruct);
– Malleolus