auto_ptr的用法

来源:互联网 发布:编程世界 编辑:程序博客网 时间:2024/05/21 15:38

auto_ptr不神秘,其作用就是当自己死了的时候,拖着别人一起死——delete其指向的东西。

 

#include <iostream>
#include <memory>
using namespace std;
class a {
public:
        ~a(){cout << "dtor" << endl;};
};
int main()
{
        std::auto_ptr<a> aa(new(a));
        return 0;
}


[root@localhost tmpc++]# g++ s9.cpp  -o s9

[root@localhost tmpc++]# ./s9
dtor