国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

13.13

2019-11-14 10:12:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

13.9 類里前面帶~的函數(shù),析構(gòu)函數(shù)用來(lái)銷毀對(duì)象釋放資源,當(dāng)沒(méi)有定義自己的析構(gòu)函數(shù)的時(shí)候編譯器會(huì)自己定義合成析構(gòu)函數(shù)。

13.10 智能指針的計(jì)時(shí)器會(huì)變?yōu)?,然后會(huì)釋放智能指針指向的內(nèi)存,然后銷毀對(duì)象。 銷毀對(duì)象,但是指針指向的內(nèi)存不會(huì)被釋放,因?yàn)槭莣eak_ptr

13.11

#include <string>class Hasptr {public: HasPtr(const std::string &s = std::string()) : ps(new std::string(s)), i(0) { } HasPtr(const HasPtr& hp) : ps(new std::string(*hp.ps)), i(hp.i) { } HasPtr& Operator=(const HasPtr& rhs){ if(this=&rhs) return this; delete ps; ps=new string (*rhs.ps); i=rhs.i; return *this; } ~HasPtr(){ delete ps; }PRivate: std::string *ps; int i;};

13.12 3次,離開(kāi)函數(shù)的時(shí)候,accum,item1,item2會(huì)被析構(gòu)。

13.13 @pezy

#include <iostream>#include <vector>#include <initializer_list>struct X { X() { std::cout << "X()" << std::endl; } X(const X&) { std::cout << "X(const X&)" << std::endl; } X& operator=(const X&) { std::cout << "X& operator=(const X&)" << std::endl; return *this; } ~X() { std::cout << "~X()" << std::endl; }};void f(const X &rx, X x){ std::vector<X> vec; vec.reserve(2); vec.push_back(rx); vec.push_back(x);}int main(){ X *px = new X; f(*px, *px); delete px; return 0;}
上一篇:代碼塊

下一篇:裝箱問(wèn)題

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 正宁县| 油尖旺区| 梅河口市| 老河口市| 仪陇县| 江安县| 荥阳市| 肃宁县| 申扎县| 广元市| 句容市| 江北区| 广西| 屯门区| 海安县| 五大连池市| 榆社县| 泽州县| 黄陵县| 沙田区| 随州市| 子长县| 鄂伦春自治旗| 琼中| 义乌市| 龙海市| 阜康市| 涞源县| 抚松县| 周口市| 稻城县| 永仁县| 青河县| 宣武区| 新和县| 同心县| 丰县| 济源市| 信宜市| 贡山| 贡山|