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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
  • 子類最好也加virtual

    查看全部
  • 解決方式:在父類的析構(gòu)函數(shù)加virtual,虛析構(gòu)函數(shù)

    查看全部
  • delete后面是父類的指針,則只會(huì)執(zhí)行父類的析構(gòu)函數(shù);

    后面是子類的指針,則會(huì)執(zhí)行子類和父類的析構(gòu)函數(shù)。

    因此在delete父類指針的時(shí)候,會(huì)造成內(nèi)存泄露。


    查看全部
  • 面向?qū)ο蟮娜筇卣鳎悍庋b、多態(tài)、繼承

    查看全部
  • https://img1.sycdn.imooc.com//5ce3fa4c0001559009810329.jpg

    靜態(tài)多態(tài)(早綁定):?

    動(dòng)態(tài)多態(tài)(晚綁定):

    查看全部
  • 在多態(tài)中,出現(xiàn)基類與派生類同名的虛函數(shù),可以父類對(duì)象實(shí)例化子類,調(diào)用子類成員函數(shù)。

    查看全部
    0 采集 收起 來源:鞏固練習(xí)

    2019-05-15

  • 多態(tài)(靜態(tài)多態(tài),動(dòng)態(tài)多態(tài))

    靜態(tài)多態(tài)(早綁定):就是函數(shù)名稱相同的兩個(gè)函數(shù),形成了重載,但是里面的參數(shù)個(gè)數(shù)不同或者說是類型不同,在主函數(shù)中調(diào)用函數(shù)的時(shí)候,會(huì)根據(jù)參數(shù)類型或者是參數(shù)的個(gè)數(shù),系統(tǒng)自動(dòng)調(diào)用函數(shù)來執(zhí)行

    動(dòng)態(tài)多態(tài)(晚綁定):a為父類,b,c都繼承了a類,a,b,c類中有共同的函數(shù),在main函數(shù)中實(shí)例化一個(gè)a的對(duì)象,分別指向b,c兩個(gè)類,這時(shí)候如果想要用實(shí)例化a的對(duì)象通過相同的函數(shù)分別指向b,c中的 與a相同的函數(shù)的時(shí)候,這是需要在a類的里面相同的函數(shù)前面加上virtual。

    查看全部
  • VIRTUAL只需要加在父類里邊(析構(gòu)函數(shù)和同名成員函數(shù))就好,析構(gòu)函數(shù)前邊加是為了防止沒有釋放子類對(duì)象的內(nèi)存導(dǎo)致內(nèi)存泄露,同名成員函數(shù)前加是為了父類實(shí)例化的對(duì)象指針能夠指向子類數(shù)據(jù)成員。

    如果我們沒有在子類當(dāng)中定義同名的虛函數(shù),那么在子類虛函數(shù)表中就會(huì)寫上父類的虛函數(shù)的函數(shù)入口地址;如果我們?cè)谧宇惍?dāng)中也定義了虛函數(shù),那么在子類的虛函數(shù)表中我們就會(huì)把原來的父類的虛函數(shù)的函數(shù)地址覆蓋一下,覆蓋成子類的虛函數(shù)的函數(shù)地址,這種情況就稱之為函數(shù)的覆蓋。


    查看全部
    1 采集 收起 來源:練習(xí)題

    2019-05-08

  • #include"Exception.h"

    #include<iostream>

    using namespace std;


    void Exception::printException()

    {

    cout <<"Exception --> printException()"<< endl;

    }


    查看全部
  • #ifndef EXCEPTION_H

    #define EXCEPTION_H


    class Exception

    {

    public:

    virtual void printException();

    virtual ~Exception(){} //虛析構(gòu)函數(shù)

    };


    #endif


    查看全部
  • #include "IndexException.h"

    #include<iostream>

    using namespace std;


    void IndexException::printException()

    {

    cout <<"提示:下標(biāo)越界"<< endl;

    }


    查看全部
  • #ifndef INDEXEXCEPTION_H

    #define INDEXEXCEPTION_H


    #include "Exception.h"

    class IndexException : public Exception

    {

    public:

    virtual void printException();

    };


    #endif


    查看全部
  • #include<iostream>

    #include"stdlib.h"

    #include "IndexException.h"


    using namespace std;


    // void test()

    // {

    // ? ? throw 10;//拋出異常 10


    // }

    // int main()

    // {

    // ? ? try

    // ? ? {

    // ? ? ? ? test();

    // ? ? }

    // ? ? catch(int)

    // ? ? {

    // ? ? ? ? cout <<"exception"<< endl;

    // ? ? }

    // ? ? system("pause");

    // ? ? return 0;

    // }


    // void test()

    // {

    // ? ? throw 0.1; //拋出異常 10


    // }

    // int main()

    // {

    // ? ? try

    // ? ? {

    // ? ? ? ? test();

    // ? ? }

    // ? ? catch(double&e)

    // ? ? {

    // ? ? ? ? cout << e << endl;

    // ? ? }

    // ? ? system("pause");

    // ? ? return 0;

    // }



    // void test()

    // {

    // ? ? throw IndexException();


    // }

    // int main()

    // {

    // ? ? try

    // ? ? {

    // ? ? ? ? test();

    // ? ? }

    // ? ? catch(IndexException &e)

    // ? ? {

    // ? ? ? ? e.printException();

    // ? ? }

    // ? ? system("pause");

    // ? ? return 0;

    // }


    // void test()

    // {

    // ? ? throw IndexException();


    // }

    // int main()

    // {

    // ? ? try

    // ? ? {

    // ? ? ? ? test();

    // ? ? }

    // ? ? catch(Exception&e)

    // ? ? {

    // ? ? ? ? e.printException();

    // ? ? }

    // ? ? system("pause");

    // ? ? return 0;

    // }


    void test()

    {

    throw IndexException();


    }

    int main()

    {

    try

    {

    test();

    }

    catch(...)

    {

    cout <<"Exception"<< endl;

    }

    system("pause");

    return 0;

    }


    查看全部
  • #include <iostream>

    #include "Bird.h"


    using namespace std;


    void Bird::foraging()

    {

    cout << "Bird --> foraging()" << endl;

    }


    void Bird::takeoff()

    {

    cout << "Bird --> takeoff()" << endl;

    }


    void Bird::land()

    {

    cout << "Bird --> land()" << endl;

    }


    查看全部
  • #ifndef Bird_H

    #define Bird_H


    #include "Flyable.h"

    #include <string>

    using namespace std;


    class Bird:public Flyable //公有繼承了Flyable

    {

    public:

    void foraging();//對(duì)于Bird類來說,其具有一個(gè)特有的成員函數(shù)foraging(覓食)

    virtual void takeoff(); //實(shí)現(xiàn)了Flyable中的虛函數(shù)takeoff和land

    virtual void land();

    };


    #endif


    查看全部

舉報(bào)

0/150
提交
取消
課程須知
本課程是C++初級(jí)課程 1、熟練掌握C++語(yǔ)言基礎(chǔ)語(yǔ)法
老師告訴你能學(xué)到什么?
1、虛函數(shù)、虛析構(gòu)函數(shù)、純虛函數(shù) 2、抽象類和接口類 3、運(yùn)行時(shí)類別異常 4、異常處理

微信掃碼,參與3人拼團(tuán)

微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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

友情提示:

您好,此課程屬于遷移課程,您已購(gòu)買該課程,無需重復(fù)購(gòu)買,感謝您對(duì)慕課網(wǎng)的支持!