【Effective C++】第三部分 资源管理类

一、

1、std::auto_ptr(其实是模板类)不用的时候 自动释放

  std::auto_ptr<Base> a1(new Child);

2、std::tr1::shared_ptr  根据引用计数来释放

  std::tr1::shared_ptr<Base> a2(new child); // 指针类型为 tr1::shared_ptr<Base> 的对象

两者的特点:

  1. 都可以可以通过a1.get()获得原始指针(复件)
  2. 这两个都重载了指针取值操作符(operator-> 和 operator*)

二、new delete成对出现

为了减少在new 的时候用了[],而delete的时候没有进行delete []name, 进行不要用数组,而是用C++ 标准程序库中的 string, vector等模板

三、第17款 注意!!!!

posted @ 2013-05-29 21:49  xiaolongxia  阅读(75)  评论(0)    收藏  举报