C++智能指針的幾種用法

 auto在c++11中已經棄用。 一、auto_ptr模板   auto_ptr與shared_ptr、unique_ptr都定義了類似指針的對象,可以將new到的地址賦給這一對象,當智能指針過期時,析構函數會調用delete函數,對象將被銷燬,由此內存可以自動被釋放。 二、shared_ptr模板   先看代碼: auto_ptr p1 (new string("hello world!");
相關文章
相關標籤/搜索