次のコード:
class Something
{
public:
~Something()
{
}
};
int main()
{
Something* s = new Something[1]; // raw pointer received from C api
std::shared_ptr<Something> p = std::shared_ptr<Something>(s);
std::vector<std::shared_ptr<Something>> v(&p,&p+1);
return 0;
}
VS Express 2010 で次のエラーが発生します。
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
何かからデストラクタを削除すると、エラーが消えます。なぜこのエラーが発生するのですか?
アップデート:
後で私は次のようなものになります:
Something* s = new Something[100];
個々の共有ポインタは他のオブジェクトに渡されます