auto_prt :它是(它所指向对象的拥有者),所以当自身对象被摧毁时候,该对象也将遭受摧毁,要求一个对象只有一个拥有者,
注意:
auto_prt 不能使用new 来分配对象给他
#include <iostream>
#include <memory>using namespace std;
template <class T>
void bad_print(auto_ptr<T> f){
cout<<*f;
}
int _tmain(int argc, _TCHAR* argv[])
{
auto_ptr<int> p(new int);
*p = 42;
bad_print(p); //auot_ptr 指针在作为函数参数专递和函数的返回值的时候,会转让所属权力,就会释放掉当前指的对象