freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

ccp20xx_(編輯修改稿)

2025-08-28 17:25 本頁面
 

【文章內(nèi)容簡介】 出現(xiàn):FlyBug構(gòu)造函數(shù)的參數(shù)、常量 問題:如果派生類沒有添加任何數(shù)據(jù)成員,是否需要構(gòu)造函數(shù)? 是 ,派生類的構(gòu)造函數(shù)可以為空,但是必須存在 int main() { FlyBug fb ( 2,3,4)。 ()。 = 1。 = 2 。 // error. nLegs is private return 0。 } ? 在創(chuàng)建派生類的對象時,需要調(diào)用基類的構(gòu)造函數(shù): 初始化派生類對象中從基類繼承的成員。 在執(zhí)行一個派生類的構(gòu)造函數(shù)之前, 總是先執(zhí)行基類的構(gòu)造函數(shù) ? 調(diào)用基類構(gòu)造函數(shù)的兩種方式 ?顯式方式:在派生類的構(gòu)造函數(shù)中,為基類的構(gòu)造函數(shù)提供參數(shù) derived::derived(arg_derivedlist):base(arg_baselist) ?隱式方式:在派生類的構(gòu)造函數(shù)中,省略基類構(gòu)造函數(shù)時,派生類的構(gòu)造函數(shù)則自動調(diào)用基類的默認(rèn)構(gòu)造函數(shù) ? 派生類的析構(gòu)函數(shù)被執(zhí)行時, 執(zhí)行完派生類的析構(gòu)函數(shù)后,自動調(diào)用基類的析構(gòu)函數(shù) include iostream using namespace std。 class Base { public: int n。 Base(int i):n(i) { cout Base n constructed endl。 } ~Base() { cout Base n destructed endl。 } }。 class Derived: public Base { public: Derived(int i):Base(i) { cout Derived constructed endl。 } ~Derived() { cout Derived destructed endl。} }。 int main() { Derived Obj(3)。 return 0。 } 輸出結(jié)果 : Base 3 constructed Derived constructed Derived destructed Base 3 destructed 北京大學(xué) 《 程序設(shè)計實習(xí) 》 課程 class Skill{ public: Skill(int n) { } }。 class FlyBug: public Bug { int nWings。 Skill sk1, sk2。 public: FlyBug( int legs, int color, int wings)。 }。 FlyBug::FlyBug( int legs, int color, int wings): Bug(legs,color),sk1(5),sk2(color) { nWings = wings。 } 包含成員對象的派生類的構(gòu)造函數(shù) 表達(dá)式中可以出現(xiàn):FlyBug構(gòu)造函數(shù)的參數(shù)、常量 北京大學(xué) 《 程序設(shè)計實習(xí) 》 課程 ? 在創(chuàng)建派生類的對象時,在執(zhí)行一個派生類的構(gòu)造函數(shù) 之前 1. 調(diào)用 基類 的構(gòu)造函數(shù):初始化派生類對象中從基類繼承的成員 2. 調(diào)用 成員對象類 的構(gòu)造函數(shù):初始化派生類對象中成員對象 ? 派生類的析構(gòu)函數(shù)被執(zhí)行時, 執(zhí)行完 派生類的析構(gòu)函數(shù)后, 1. 調(diào)用 成員對象類 的析構(gòu)函數(shù) 2. 調(diào)用 基類 的析構(gòu)函數(shù) 基類 成員對象類 派生類 構(gòu)造 構(gòu)造 析構(gòu) 析構(gòu) 北京大學(xué) 《 程序設(shè)計實習(xí) 》 課程 public繼承的賦值兼容規(guī)則 ? 派生類的對象可以賦值給基類對象 b = d。 ? 派生類對象可以初始化基類引用 base amp。 br = d。 ? 派生類對象的地址可以賦值給基類指針 base * pb = amp。 d。 ? 如果派生方式是 private或 protected,則上述三條不可行 class base { }。 class derived : public base { }。 base b。 derived d。 問題:反過來是否可以?為什么? 北京大學(xué) 《 程序設(shè)計實習(xí) 》 課程 protected繼承和 private繼承 ? protected繼承時,基類的 public成員和 protected成員成為派生類的 protected成員。 ? private繼承時,基類的 public成員成為派生類的 private成員,基類的 protected成員成為派生類的不可訪問成員。 ? protected和 private繼承不是“是”的關(guān)系。 class base { }。 class derived : protected base { }。 base b。 derived d。 北京大學(xué) 《 程序設(shè)計實習(xí) 》 課程 基類與派生類的指針強(qiáng)制轉(zhuǎn)換 ? 派生類對象的指針可以直接賦值給基類指針 ptrBase = amp。objDerived。 ? ptrBase指向的是一個 Derived類的對象 ? *ptrBase可以看作一個 Base類的對象,訪問它的 public成員 ?直接通過 ptrBase, 不能夠訪問 objDerived由 Derived類擴(kuò)展的成員 ? 通過強(qiáng)制指針類型轉(zhuǎn)換,可以把 ptrBase轉(zhuǎn)換成Derived類的指針 ptrBase = amp。objDerived。 ptrDerived = (Derived * ) ptrBase。 ?程序員要 保證 ptrBase指向的是一個 Derived類的對象 ,否則會出錯 include iostream using namespace std。 class Base { public:
點(diǎn)擊復(fù)制文檔內(nèi)容
醫(yī)療健康相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1