1auto_ptr作为函数参数#include "stdafx.h"
 2auto_ptr作为函数参数
 3auto_ptr作为函数参数#include <iostream>
 4auto_ptr作为函数参数
 5auto_ptr作为函数参数#include <memory>
 6auto_ptr作为函数参数
 7auto_ptr作为函数参数using namespace std;
 8auto_ptr作为函数参数
 9auto_ptr作为函数参数 
10auto_ptr作为函数参数
11auto_ptr作为函数参数template <class T>
12auto_ptr作为函数参数
13auto_ptr作为函数参数ostream& operator<< (ostream& os, const auto_ptr<T> &p)
14auto_ptr作为函数参数
15}
如果不用引用,在函数传参的时候会将指针的控制权交给函数的参数,之后程序就会出问题。
如果不用const,还没想出会有什么后果。

使用auto_ptr需注意的地方:
1 它不能用作数组或容器的对象。
2
它不能进行一般意义的赋值和复制。
3
它的指针算数没有意义。
你最好不要用它来传递参数,当不得不用的时候必须用const引用才行。
5 同时不能有两个以上的auto_ptr指向同一个值。
参考:
http://blog.csdn.net/vagrxie/archive/2007/10/12/1821091.aspx

相关文章: