以下代码:
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中删除析构函数,错误消失,为什么我会收到这个错误?
更新:
稍后我会有类似的东西:
Something* s = new Something[100];
并且各个共享指针将被传递给其他对象