I have working in large application which contain c and cpp. The all files saved as cpp extension but the code is written in c- style. I mean it is define structure rather than
To use a std::shared_pointer
with malloc()
and free()
you should specify a custom deleter. This should do it
std::shared_ptr ptr(static_cast(malloc(sizeof(T))), free);
As long as you do not pass around the result of std::shared_ptr
, your pointer is safe.
Edit: Added casting the result of malloc()
to T*
.