如果没有,下面的代码会产生内存泄漏。可以肯定地说微软错过了这一点吗?
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
template <typename T>
class class_leak
{
private:
T *p_;
public:
class_leak(T *p) :
p_(p)
{}
~class_leak()
{
delete p_;
}
};
int main(int /*argc*/, char * /*argv*/[]) {
int *x = new int(10);
class_leak<int> cl(x);
_CrtDumpMemoryLeaks();
}
产品:
Detected memory leaks!
Dumping objects ->
{56} normal block at 0x000D1540, 4 bytes long.
Data: < > 0A 00 00 00
Object dump complete.
The program '[4584] unique_ptr.exe: Native' has exited with code 0 (0x0).