##shared_ptrにresetや代入して動かしてみた(ctor/dtor)
SharedPtrTestという何の変哲もないクラスを作って実験
その1
{
std::shared_ptr<SharedPtrTest> sharedPtr = nullptr;
auto temp_SharedPtr1(new SharedPtrTest(L"1"));
sharedPtr.reset(temp_SharedPtr1);
auto temp_SharedPtr2(new SharedPtrTest(L"2"));
sharedPtr.reset(temp_SharedPtr2);
auto temp_SharedPtr3(new SharedPtrTest(L"3"));
sharedPtr.reset(temp_SharedPtr3);
auto temp_SharedPtr4(new SharedPtrTest(L"4"));
sharedPtr.reset(temp_SharedPtr4);
}
その2
{
std::shared_ptr<SharedPtrTest> sharedPtr = nullptr;
SharedPtrTest* temp_SharedPtr1 = new SharedPtrTest(L"1");
sharedPtr.reset(temp_SharedPtr1);
SharedPtrTest* temp_SharedPtr2 = new SharedPtrTest(L"2");
sharedPtr.reset(temp_SharedPtr2);
SharedPtrTest* temp_SharedPtr3 = new SharedPtrTest(L"3");
sharedPtr.reset(temp_SharedPtr3);
SharedPtrTest* temp_SharedPtr4 = new SharedPtrTest(L"4");
sharedPtr.reset(temp_SharedPtr4);
}
その3
{
std::shared_ptr<SharedPtrTest> sharedPtr = nullptr;
std::shared_ptr<SharedPtrTest> temp_SharedPtr1(new SharedPtrTest(L"1"));
sharedPtr = temp_SharedPtr1;
std::shared_ptr<SharedPtrTest> temp_SharedPtr2(new SharedPtrTest(L"2"));
sharedPtr = temp_SharedPtr2;
std::shared_ptr<SharedPtrTest> temp_SharedPtr3(new SharedPtrTest(L"3"));
sharedPtr = temp_SharedPtr3;
std::shared_ptr<SharedPtrTest> temp_SharedPtr4(new SharedPtrTest(L"4"));
sharedPtr = temp_SharedPtr4;
}
###その1の実行結果
id[1] : Ctor
id[2] : Ctor
id[1] : Dtor
id[3] : Ctor
id[2] : Dtor
id[4] : Ctor
id[3] : Dtor
id[4] : Dtor
###その2の実行結果
id[1] : Ctor
id[2] : Ctor
id[1] : Dtor
id[3] : Ctor
id[2] : Dtor
id[4] : Ctor
id[3] : Dtor
id[4] : Dtor
###その3の実行結果
id[1] : Ctor
id[2] : Ctor
id[3] : Ctor
id[4] : Ctor
id[3] : Dtor
id[2] : Dtor
id[1] : Dtor
id[4] : Dtor