0

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

Sharad
  • 1
  • 1
  • 1
    "I wanted to ask if I could pass a deleter type to the shared_ptr created with make_shared" Could you clarify that question by actually asking about *that*, instead of talking mostly about incomplete types which have nothing to do with what you're trying to do? Just restate your question. – Nicol Bolas Jun 03 '12 at 21:06

1 Answers1

3

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • The type is complete at the time of creation ie when new or make_shared is called. – Sharad Jun 03 '12 at 20:49
  • 2
    @Sharad: Then what error are you getting in the compiler? And where are these uses of `make_shared`? – Nicol Bolas Jun 03 '12 at 20:51
  • Sorry I guess i missed the point in my question. I was wondering if I could pass a deleter to the newly created shared_ptr? – Sharad Jun 03 '12 at 20:57