shared_ptr(p.get());为什么错?该怎么解决
shared_ptr<int>(p.get());为什么错?
运行时报错 _CrtIsValidHeapPointer(block)
还有下面这个程序也一样报错,为啥?
------解决思路----------------------
重复delete了
#include <memory>
using namespace std;
int main()
{
shared_ptr<int> p(new int(42));
shared_ptr<int>(p.get());
}
运行时报错 _CrtIsValidHeapPointer(block)
还有下面这个程序也一样报错,为啥?
#include <memory>
using namespace std;
int main()
{
auto sp = make_shared<int>();
auto p = sp.get();
delete p;
}
------解决思路----------------------
重复delete了