using make_shared with incomplete types

615 views Asked by At

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

1

There are 1 answers

3
Nicol Bolas On

No, make_shared cannot pass a deleter object to the shared_ptr it creates. And generally, you wouldn't need to. Since it uses new (placement new specifically) to create the pointer, it will need to be deleted by calling the destructor. So there's not much that you could do, since make_shared manages the memory directly.