Tried this program out of curiosity to understand behavior of shared_ptr over raw pointers. I hope the problem could be double delete but here I am facing other:
MyClass *raw_ptr = new MyClass();
shared_ptr<MyClass> sptr1(raw_ptr);
shared_ptr<MyClass> sptr2 = sptr1;
cout << sptr1.use_count() << endl; // prints 2
sptr1.reset(); // occurs Segmentation Fault here
Expected Behavior: reduce the count to 1 and moves control to next line.
Aucun commentaire:
Enregistrer un commentaire