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

為了賬號安全,請及時綁定郵箱和手機立即綁定

正在回答

6 回答

class Bus :public Movable 打錯了、、、

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

加了還有錯嗎,錯誤提示是你沒有包含 typeinfo,如果加了還有錯,加了過后的錯誤提示是什么,貼出來看看,或者加我,我給你發(fā)代碼。

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

#include <iostream>

#include <stdlib.h>

#include <string>

#include <typeinfo>

using namespace std;


/**

?* 定義移動類:Movable

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

?*/

class Movable

{

public:

? ? virtual void move() = 0;

};


/**

?* 定義公交車類:Bus

?* 公有繼承移動類

?* 特有方法carry

?*/

class Bus : public Movable

{

public:

? ? virtual void move()

? ? {

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

? ? }

? ??

? ? void carry()

? ? {

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

? ? }

};


/**

?* 定義坦克類:Tank

?* 公有繼承移動類

?* 特有方法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(Movable))

? ? {

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

? ? ? ? tank->fire();

? ? }

}


int main(void)

{

? ? Bus b;

? ? Tank t;

? ? doSomething(&b);

? ? doSomething(&t);

? ? return 0;

}



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

define_ray 提問者

又復(fù)制一遍干嘛?你看我那個哪里錯了??指出錯的地方就行
2015-12-24 回復(fù) 有任何疑惑可以回復(fù)我~
#include?<iostream>
#include?<stdlib.h>
#include?<string>
#include?<typeinfo>
using?namespace?std;

/**
?*?定義移動類:Movable
?*?純虛函數(shù):move
?*/
class?Movable
{
public:
????virtual?void?move()?=?0?;
};

/**
?*?定義公交車類:Bus
?*?公有繼承移動類
?*?特有方法carry
?*/
class?Bus?:?public?Movalbe
{
public:
????virtual?void?move()
????{
????????cout?<<?"Bus?--?move"?<<?endl;
????}
????
????void?carry()
????{
????????cout?<<?"Bus?--?carry"?<<?endl;
????}
};

/**
?*?定義坦克類:Tank
?*?公有繼承移動類
?*?特有方法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;
}

幫忙看下哪里不對……

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

用了?typeid?了,需要?#include?<typeinfo>?才行

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

define_ray 提問者

加了還是不行,代碼在下面,幫忙看看……
2015-12-24 回復(fù) 有任何疑惑可以回復(fù)我~

你需要在前面加上#include<typeinfo>這個頭文件

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

define_ray 提問者

加上之后還有錯……
2015-12-24 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

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

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

進入課程

如圖,哪里錯了??

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

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

幫助反饋 APP下載

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

公眾號

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