关于智能指针
第一个问题
while(1)
{
shared_ptr<int> p(new int[10], [](int* x){delete[] x;});
shared_ptr<int> p1(new int[1000]);
}
如上,为什么此段代码不会涨内存?
第二个问题
shared_ptr<int> pValue3(new int(40));
shared_ptr<int> pValue5(new int[40], [](int* x){delete[] x;});
shared_ptr<int> pValue6(pValue3, [](int* x){delete x;});
如上,为什么显示第三句代码是错的,而第二句代码是对的?
第三个问题
unique_ptr<int> pUinque(new int(30));
shared_ptr<int> pValue6(pUinque);
如上,为什么第二句代码是错的?
第四个问题
shared_ptr<int> pValue = make_shared<int>(20); //make_shared是安全的分配和使用动态内存的方法,推荐使用这种方法
shared_ptr<int> pValue2 = make_shared<int>(30);
pValue.reset(pValue2);
pValue.reset(pValue2, [](int* x){delete x;});
如上,第三句代码和第四句代码是错的?