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

正文內(nèi)容

[工程科技]第八章-繼承與派生-資料下載頁

2025-01-19 12:59本頁面
  

【正文】 函數(shù),再基類析構(gòu)函數(shù) ?復(fù)習(xí):析構(gòu)函數(shù)的功能 在對象消亡之前進(jìn)行必要的清理工作 class Tcolor { private: string _color。 public: TColor(string color=BLACK) { coutTColor構(gòu)造函數(shù) endl。 _color=color。 } ~TColor( ) {coutTColor析構(gòu)函數(shù) endl。} }。 // include iostream include string using namespace std。 class Tpoint{ protected: int _x, _y。 public: TPoint(int x=0, int y=0) { coutTPoint構(gòu)造函數(shù) (x,y)endl。 _x=x。 _y=y。 } ~TPoint( ){coutTPoint析構(gòu)函數(shù) (_x,_y)endl。} }。 例 87 派生類析構(gòu)函數(shù) class TEllipse:public TShape { private: TPoint* pLeftFocus, RightFocus。 public: TEllipse( ):TShape( ), RightFocus(2,0) { cout派生類構(gòu)造函數(shù) endl。 pLeftFocus=new TPoint(1,0)。 } ~TEllipse( ) { cout派生類析構(gòu) endl。 if(pLeftFocus) delete pLeftFocus。 } }。 void main( ) { TEllipse elps。 } class TShape{ protected: TColor* pColor。 public: TShape( ) { cout基類構(gòu)造函數(shù) endl。 pColor=new TColor。 } ~TShape( ){ cout基類析構(gòu)函數(shù) endl。 if(0!=pColor) delete pColor。 } }。 例 派生類析構(gòu)函數(shù) 2022/2/16 北京 郵電 大 學(xué) 信息 與 通信工程 學(xué) 院 56 轉(zhuǎn)換與繼承 轉(zhuǎn)換與繼承 ? 深入了解派生類的成員的布局方式 ? 派生類對象與基類對象之間轉(zhuǎn)換的一般規(guī)則 2022/2/16 北京 郵電 大 學(xué) 信息 與 通信工程 學(xué) 院 58 派生類到基類的轉(zhuǎn)換 轉(zhuǎn)換與繼承 ? 派生類到基類的轉(zhuǎn)換有以下三種情況: – 派生類對象轉(zhuǎn)換為基類對象; – 基類對象指針指向派生類對象; – 用派生類對象初始化基類對象的引用。 public: TCircle(int mx=0, int my=0, int mr=1): TShape(mx, my) { r = mr。 } void Show( ) {TShape::Show()。cout\tr=r。 } }。 void main( ){ TShape s。 TCircle c(1,2,3)。 coutTShape s\t。 ( )。 coutendl。 coutTCircle c\t。 ( )。 coutendl。 s = c。 //用派生類對象為基類對象賦值 // s = static_castTShape(c)。 couts=c\t\t。 ()。 coutendl。 } // include iostream using namespace std。 class TShape { protected: int x, y。 public: TShape(int mx=0, int my=0) { x=mx。 y=my。 } void Show( ) {coutx=x\t y=y。} }。 class TCircle : public TShape { protected: int r。 例 88派生類對象轉(zhuǎn)換為基類對象 void main( ){ TCircle c(1,2,3)。 coutTCircle c\t。 ( )。 coutendl。 //TShape* ps = amp。c。 TShape* ps = dynamic_castTShape*(amp。c)。 //基類對象指針指向派生類對象 if(0!=ps) { coutps=amp。c\t\t。 psShow( )。 coutendl。 } } // //本文件的代碼除了 main()函數(shù)之外,均與 Mai include iostream using namespace std。 class TShape { protected: int x, y。 public: TShape(int mx=0, int my=0) { x=mx。 y=my。 } void Show( ) {coutx=x\t y=y。} }。 class TCircle : public TShape { protected: int r。 public: TCircle(int mx=0, int my=0, int mr=1): TShape(mx, my) { r = mr。 } void Show( ) {TShape::Show()。 cout\tr=r。 } }。 例 89基類對象指針指向派生類對象 2022/2/16 北京 郵電 大 學(xué) 信息 與 通信工程 學(xué) 院 62 基類到派生類的轉(zhuǎn)換 基類到派生類的轉(zhuǎn)換 ? C++編譯器可以自動(dòng)將派生類對象轉(zhuǎn)換為基類對象(隱式類型轉(zhuǎn)換) ? 從基類到派生類的自動(dòng)轉(zhuǎn)換是不存在的 //以下代碼僅為示例 TShape s。 TCircle c = s。 //錯(cuò)誤!不能將基類轉(zhuǎn)換為派生類 TCircle* pc = amp。s。 //錯(cuò)誤!不能將基類轉(zhuǎn)換為派生類 TCircleamp。 rc = s。 //錯(cuò)誤!不能將基類轉(zhuǎn)換為派生類 總結(jié) ? 類的繼承性及其相關(guān)概念 – 派生類可以以公有 、 保護(hù)和私有 3種方式繼承基類 – 派生類能夠繼承基類中除構(gòu)造函數(shù)和析構(gòu)函數(shù)之外的所有成員 – 派生類定義自己的構(gòu)造函數(shù)和析構(gòu)函數(shù) 。 在定義派生類的構(gòu)造函數(shù)時(shí) , 不僅要考慮派生類新增數(shù)據(jù)成員的初始化 , 還要注意在成員初始化列表中對基類構(gòu)造函數(shù)的調(diào)用和內(nèi)嵌對象數(shù)據(jù)成員進(jìn)行初始化 。
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1