1

Converting this to a shared ptr is easy:

MyObject * myObject = new MyObject( int n );
auto myObject = make_shared<MyObject>( n );

But what if my code is an array?

char * myChars = new char[n];
auto myChars = make_shared<char>????

I want the resulting pointer to point to an array which calls the default dtor on each element when it goes out of scope. Is that possible?

manuell
  • 7,528
  • 5
  • 31
  • 58
rtischer8277
  • 496
  • 6
  • 27

1 Answers1

1

Well, likely, in C++11 you may use shared_ptr on arrays, but only if you manually provide appropriate deleter. Unlike unique_ptr which explicitly has partial specialization on T[], shared_ptr doesn't have one, but it may be supplied with a custom deleter.

user3159253
  • 16,836
  • 3
  • 30
  • 56