Here I am creating dynamically allocated array of S objects and I expect them to be destroyed by unique_ptr, which doesn't happen and I get this error
Command terminated by signal 11
and that means the program accessed memory which it shouldn't have accessed as far as I am concerned.
#include <iostream>
#include <memory>
class S{
public:
S(){std::cout<<"Constructor\n";}
~S(){std::cout<<"Destructor\n";}
};
int main() {
S* arr=new S[4];
{
using namespace std;
unique_ptr<S> ptr=unique_ptr<S>(arr);
}
}
` will assume it is managing a single object and effectively do `delete arr`. Since `arr` was initialised using an the array form of operator `new`, the behaviour is undefined.– Peter Nov 03 '20 at 13:48(4);`– Nikos C. Nov 03 '20 at 13:53