I am trying to switch my code to use make_shared<type>()
but I have a lot of incomplete types (complete at the time of creation) and was wondering if there is anyway make_shared would work with incomplete types or allow me to pass a deleter type.
I looked around and didn't find any posts related to this so either this just works ?? or I am overlooking something basic.
#define NEW_PARAMS(Type, ...) ::std::shared_ptr<Type>(new (Type)(__VA_ARGS__), ::std::default_delete<Type>())
Above is the macro I use to create new objects. Would like to convert this to
#define NEW_PARAMS(Type, ...) ::std::make_shared<Type>(__VA_ARGS__, ::std::default_delete<Type>())
EDIT: Just to clarify I wanted to ask if I could pass a deleter type to the shared_ptr
created with make_shared
No,
make_shared
cannot pass a deleter object to theshared_ptr
it creates. And generally, you wouldn't need to. Since it usesnew
(placementnew
specifically) to create the pointer, it will need to be deleted by calling the destructor. So there's not much that you could do, sincemake_shared
manages the memory directly.