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

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

13.3

2019-11-11 04:03:30
字體:
來源:轉載
供稿:網友

13.29

swap(lhs.ps, rhs.ps);swap(lhs.i, rhs.i);

他們調用的是另一個版本的swap而不是 swap(Hasptr&, HasPtr&) 所以并不會遞歸

13.30

#include <string>#include <iostream>class HasPtr {public: friend void swap(HasPtr&, HasPtr&); 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 &hp) { auto new_p = new std::string(*hp.ps); delete ps; ps = new_p; i = hp.i; return *this; } ~HasPtr() { delete ps; } void show() { std::cout << *ps << std::endl; }PRivate: std::string *ps; int i;};inlinevoid swap(HasPtr& lhs, HasPtr& rhs){ using std::swap; swap(lhs.ps, rhs.ps); swap(lhs.i, rhs.i); std::cout << "call swap(HasPtr& lhs, HasPtr& rhs)" << std::endl;}

13.31

#include <string>#include <iostream>class HasPtr {public: friend void swap(HasPtr&, HasPtr&); friend bool operator<(const HasPtr &lhs, const HasPtr &rhs); 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=(HasPtr tmp) { this->swap(tmp); return *this; } ~HasPtr() { delete ps; } void swap(HasPtr &rhs) { using std::swap; swap(ps, rhs.ps); swap(i, rhs.i); std::cout << "call swap(HasPtr &rhs)" << std::endl; } void show() const { std::cout << *ps << std::endl; }private: std::string *ps; int i;};void swap(HasPtr& lhs, HasPtr& rhs){ lhs.swap(rhs);}bool operator<(const HasPtr &lhs, const HasPtr &rhs){ return *lhs.ps < *rhs.ps;}

13.32 不會 類指針并沒有分配內存的操作,所以并不會受益


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 理塘县| 吉水县| 腾冲县| 南昌县| 汝南县| 云南省| 长汀县| 桐乡市| 临泉县| 大悟县| 龙川县| 邵阳县| 遵义县| 汝城县| 锡林郭勒盟| 芷江| 马尔康县| 三亚市| 赣榆县| 塔城市| 遂宁市| 秦皇岛市| 深水埗区| 长垣县| 昭觉县| 建水县| 托克逊县| 晋宁县| 建始县| 潜江市| 迁安市| 滦南县| 馆陶县| 昔阳县| 阳高县| 梓潼县| 凤阳县| 灌云县| 监利县| 湖南省| 五华县|