<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      派生類的拷貝控制成員

      測試代碼

      #include "../head.h"
      
      class Quote {
      public:
      	Quote() {cout << "default constructing Quote" << endl;};
      	Quote(const string &book, double sales_price) : 
      		bookNo(book), price(sales_price) {
      			cout << "Quote:cosntructor taking 2 parameters" << endl;
      		}
      
      	Quote(const Quote &q) : bookNo(q.bookNo), price(q.price) {
      		cout << "Quote:copy constructing Quote" << endl;
      	}
      	Quote& operator=(const Quote &rhs) {
      		bookNo = rhs.bookNo; price = rhs.price;
      		cout << "Quote:copy=()" << endl;
      		return *this;
      	}
      	
      	Quote(const Quote &&q) noexcept : 
      		bookNo(move(q.bookNo)), price(move(q.price)) {
      			cout << "Quote:move constructing" << endl;
      		}
      	Quote& operator=(const Quote &&rhs) {
      		bookNo = move(rhs.bookNo); price = move(rhs.price); 
      		cout << "Quote:move=()" << endl;
      		return *this;
      	}
      
      	string isbn() const {return bookNo;}
      	virtual double net_price(size_t n) const {return n * price;}
      	virtual ~Quote() {cout << "destructing Quote" << endl;};
      protected:
      	double price = 0.0;
      private:
      	string bookNo;
      };
      
      class Disc_quote : public Quote {
      public:
      	Disc_quote() {cout << "default constructing Disc_quote" << endl;}
      	Disc_quote(const string &book, double price, size_t qty, double disc) : 
      		Quote(book, price), quantity(qty), discount(disc) {
      			cout << "Disc_quote:constructor taking 4 parameters" << endl;
      		}
      
      	Disc_quote(const Disc_quote &q) : Quote(q) {
      		cout << "Disc_quote:copy constructing Disc_quote" << endl;
      	}
      	Disc_quote& operator=(const Disc_quote &rhs) {
      		Quote::operator=(rhs);
      		cout << "Disc_quote:copy=()" << endl;
      		return *this;
      	}
      
      	Disc_quote(const Disc_quote &&q) noexcept :
      		Quote(move(q)) {
      			cout << "Disc_quote:move constructing" << endl;
      		}
      	Disc_quote& operator=(const Disc_quote &&rhs) {
      		Quote::operator=(move(rhs));
      		cout << "Disc_quote:move=()" << endl;
      		return *this;
      	}
      
      	double net_price(size_t n) const override {
      		if (n >= quantity) return n * (1 - discount) * price;
      		else return n * price;
      	}
      	~Disc_quote() {cout << "destructing Disc_quote" << endl;}
      protected: 
      	size_t quantity = 0;
      	double discount = 0.0;
      };
      
      void print_total(ostream &os, const Quote &item, size_t n) {
      	double ret = item.net_price(n);
      	os << "ISBN: " << item.isbn() << "# sold: " << n << "total due: " << ret << endl;
      }
      
      int main(int argc, char** argv) {
      	Quote item1("hello", 10);
      	Disc_quote item2("hello", 10, 5, 0.1);
      	cout << "<==copy constructor test ==>" << endl;
      	Disc_quote item3(item2);
      	Disc_quote item4;
      	item4 = item3;
      	cout << "<==move constructor test ==>" << endl;
      	Disc_quote item5(move(item2));
      	Disc_quote item6;
      	item6 = move(item5);
      	cout << "<==destructing test ==>" << endl;
      	return 0;
      }
      

      輸出

      Quote:cosntructor taking 2 parameters
      Quote:cosntructor taking 2 parameters
      Disc_quote:constructor taking 4 parameters
      <==copy constructor test ==>
      Quote:copy constructing Quote
      Disc_quote:copy constructing Disc_quote
      default constructing Quote
      default constructing Disc_quote
      Quote:copy=()
      Disc_quote:copy=()
      <==move constructor test ==>
      Quote:move constructing
      Disc_quote:move constructing
      default constructing Quote
      default constructing Disc_quote
      Quote:move=()
      Disc_quote:move=()
      <==destructing test ==>
      destructing Disc_quote
      destructing Quote
      destructing Disc_quote
      destructing Quote
      destructing Disc_quote
      destructing Quote
      destructing Disc_quote
      destructing Quote
      destructing Disc_quote
      destructing Quote
      destructing Quote
      

      這是《C++ primer》15-26的題,主要就是為了測試派生類拷貝控制操作的行為,實驗結(jié)果與預(yù)期相同

      1 派生類的默認構(gòu)造函數(shù)會先運行基類的默認構(gòu)造函數(shù),將基類中的數(shù)據(jù)成員初始化,然后執(zhí)行自己的默認構(gòu)造函數(shù),將數(shù)據(jù)成員初始化
      2 派生類使用拷貝構(gòu)造函數(shù)時會先運行基類的拷貝構(gòu)造函數(shù),然后再運行自己的拷貝構(gòu)造函數(shù),對于拷貝賦值運算符、移動構(gòu)造函數(shù)、移動賦值運算符也都是類似的操作
      3 派生類銷毀時先執(zhí)行自己的析構(gòu)函數(shù),再執(zhí)行基類的析構(gòu)函數(shù)

      posted @ 2019-04-22 14:36  start-from-ling  閱讀(162)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 在线看国产精品自拍内射| 99精品国产一区二区三区不卡 | 国产精品日韩av一区二区| 亚洲永久精品ww47永久入口 | 国产又色又爽又黄的在线观看| 亚洲少妇人妻无码视频| 精品无码久久久久久尤物| 日韩老熟女av搜索结果| 国产极品美女高潮无套| 被黑人巨大一区二区三区| 国产亚洲精品第一综合另类| 国产精久久一区二区三区| 亚洲av日韩av一区久久| 九九热在线视频免费播放| 国产成人片无码视频在线观看| 国产91精品一区二区蜜臀| 国产午夜影视大全免费观看| 国产精品久久中文字幕| 久久精品国产亚洲av熟女| 99久久亚洲综合精品成人网| 国产成人av免费观看| 麻豆国产传媒精品视频| 亚洲an日韩专区在线| 中文字幕无码视频手机免费看| 国内不卡一区二区三区| 盐山县| 国产 麻豆 日韩 欧美 久久| 好姑娘高清影视在线观看| 国产成人午夜精品福利| 亚洲大老师中文字幕久热| 高级艳妇交换俱乐部小说| 日本一区二区a√成人片| 国产成人不卡一区二区| 国产又黄又硬又粗| 人妻在线中文字幕| 国产精品久久久天天影视香蕉 | 真人无码作爱免费视频| 亚洲欧美日产综合在线网| 财经| 亚洲一级特黄大片一级特黄| 特级毛片在线大全免费播放|