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

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

為什么我加上了?#include <typeinfo>出現(xiàn)了更多的問(wèn)題了。。

#include <iostream>

#include <stdlib.h>

#include <string>

#include <typeinfo>

using namespace std;


/**

?* 定義移動(dòng)類:Movable

?* 純虛函數(shù):move

?*/

class Movable

{

public:

? ? virtual void move()=0;

};


/**

?* 定義公交車類:Bus

?* 公有繼承移動(dòng)類

?* 特有方法carry

?*/

class Bus : public Movable

{

public:

? ? virtual void move()

? ? {

? ? ? ? cout << "Bus -- move" << endl;

? ? }

? ??

? ? ?void? carry()

? ? {

? ? ? ? cout << "Bus -- carry" << endl;

? ? }

};


/**

?* 定義坦克類:Tank

?* 公有繼承移動(dòng)類

?* 特有方法fire

?*/

class Tank :public Movable

{

public:

? ? virtual void move()

? ? {

? ? ? ? cout << "Tank -- move" << endl;

? ? }


? void fire()

? ? {

? ? ? ? cout << "Tank -- fire" << endl;

? ? }

};


/**

?* 定義函數(shù)doSomething含參數(shù)

?* 使用dynamic_cast轉(zhuǎn)換類型

?*/

void doSomething(Movable *obj)

{

? ? obj->move();


? ? if(typeid(*obj)=typeid(Bus))

? ? {

? ? ? ?Bus *bus=dynamic_cast<Bus *>(obj);

? ? ? ? bus->carry();

? ? }


? ? if(typeid(*obj)=typeid(Tank))

? ? {

? ? ? ? Tank *tank=dynamic_cast<Tank *>(obj);

? ? ? ? tank->fire();

? ? }

}


int main(void)

{

? ? Bus b;

? ? Tank t;

? ? doSomething(&b);

? ? doSomething(&t);

? ? return 0;

}



正在回答

1 回答

我知道了,,==寫成=了,舒服了。。

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)入課程

為什么我加上了?#include <typeinfo>出現(xiàn)了更多的問(wèn)題了。。

我要回答 關(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)