第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

void flyMatch(Flyable* f1, Flyable * f2)

為什么形參Flyable* f1可以調(diào)用plane的指針, 是應(yīng)為plane是Flyable的子類么??

正在回答

1 回答

/**
這就是所謂的多態(tài)啊
*/

class?Father{
public:
????virtual?void?func(){std::cout<<"father"<<std::endl;}
};

class?Child:public?Father{
public:
????//?override?Father's?function?func()
????void?func(){std::cout<<"child"<<std::endl;}
};

//?usage
Father?*f?=?new?Father();
f->func();?//?output?"father"
Child?c?=?new?Child();
c->func();?//?output?"child"

Father?*pf?=?NULL;
Father?*pc?=?NULL;

pf?=?c;?//?pointer?of?Father?type?points?to?object?of?Child?which?is?Father's?subclass
pf->func();?//?output?"child",?because?the?real?type?of?the?object?is?Child.?(polymorphic)

//pc?=?f;?//?this?is?WRONG!!?child?pointer?can?not?points?to?father?object
pc?=?dynamic_cast<Child*>(pf);?//?right


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
C++遠(yuǎn)征之多態(tài)篇
  • 參與學(xué)習(xí)       66225    人
  • 解答問(wèn)題       329    個(gè)

本教程將帶領(lǐng)大家體會(huì)面向?qū)ο笕筇匦灾械亩鄳B(tài)特性

進(jìn)入課程

void flyMatch(Flyable* f1, Flyable * f2)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)