将一个共享指针分配给另一个共享指针是否会释放后者管理的内存?让
typedef shared_ptr<char> char_ptr_t;
char_ptr_t pA(new char('A'));
char_ptr_t pB(new char('B'));
现在,以下语句是否释放内存'A'
?
/*1*/ pA = pB;
还是我需要明确释放它:
/*2*/ pA.reset();
/*3*/ pA = pB;
而且,以下代码是否有效实现相同的目标?
/*4*/ pA.reset(pB); //<-- is this valid? Not compiling in MSVC++ 2010, though the standard seems to allow it.