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

首頁 > 學院 > 開發設計 > 正文

13.13

2019-11-14 10:23:05
字體:
來源:轉載
供稿:網友

13.9 類里前面帶~的函數,析構函數用來銷毀對象釋放資源,當沒有定義自己的析構函數的時候編譯器會自己定義合成析構函數。

13.10 智能指針的計時器會變為0,然后會釋放智能指針指向的內存,然后銷毀對象。 銷毀對象,但是指針指向的內存不會被釋放,因為是weak_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次,離開函數的時候,accum,item1,item2會被析構。

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲周县| 浑源县| 轮台县| 吉林市| 夏河县| 遂平县| 邹城市| 广德县| 通河县| 禹城市| 阿巴嘎旗| 内黄县| 兰州市| 花莲县| 朝阳区| 汉沽区| 竹溪县| 永吉县| 璧山县| 繁昌县| 财经| 高要市| 靖江市| 天峻县| 平远县| 湟源县| 景东| 肇州县| 咸宁市| 益阳市| 光泽县| 罗田县| 额尔古纳市| 万载县| 双城市| 南宁市| 若羌县| 湾仔区| 囊谦县| 库尔勒市| 张北县|