最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
  • 子類最好也加virtual

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

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

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

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


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

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

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

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

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

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

    2019-05-15

  • 多態(tài)(靜態(tài)多態(tài),動態(tài)多態(tài))

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

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

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

    如果我們沒有在子類當(dāng)中定義同名的虛函數(shù),那么在子類虛函數(shù)表中就會寫上父類的虛函數(shù)的函數(shù)入口地址;如果我們在子類當(dāng)中也定義了虛函數(shù),那么在子類的虛函數(shù)表中我們就會把原來的父類的虛函數(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();//對于Bird類來說,其具有一個特有的成員函數(shù)foraging(覓食)

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

    virtual void land();

    };


    #endif


    查看全部

舉報

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

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

微信客服

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

幫助反饋 APP下載

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

公眾號

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

友情提示:

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