Hello,
I was playing around with smart pointers in C++ (VS2010) and encountered some unexpected behavior. Best explained by this code snippet:
// allocate the memory
Test* dynamic = new Test;
// take over the ownership
std::unique_ptr<Test> takeOver(dynamic);
// wait for ENTER to continue
std::getchar();
// clear the memory
takeOver.reset();
// shouldn't this cause a crash?
dynamic->reference(1);
// oddly enough the following line doesn't cause an immediate crash either
// if I press ENTER next though, it crashes and the debugger says that it might be due to heap corruption
//delete dynamic;
std::getchar();
Output I get from the application is the following: