• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > C++構(gòu)造函數(shù)與析構(gòu)函數(shù)的使用方法

    C++構(gòu)造函數(shù)與析構(gòu)函數(shù)的使用方法

    作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
    構(gòu)造函數(shù),是一種特殊的方法 。主要用來在創(chuàng)建對象時(shí)初始化對象, 即為對象成員變量賦初始值,總與new運(yùn)算符一起使用在創(chuàng)建對象的語句中 。特別的一個(gè)類可以有多個(gè)構(gòu)造函數(shù) ,可根據(jù)其參數(shù)個(gè)數(shù)的不同或參數(shù)類型的不同來區(qū)分它們 即構(gòu)造函數(shù)的重載。

    析構(gòu)函數(shù)(destructor) 與構(gòu)造函數(shù)相反,當(dāng)對象脫離其作用域時(shí)(例如對象所在的函數(shù)已調(diào)用完畢),系統(tǒng)自動(dòng)執(zhí)行析構(gòu)函數(shù)。

    #include
    class animal
    {
    public:
    animal()
    {
    cout<<"hello"<}
    ~animal()
    {
    cout<<"析構(gòu)函數(shù)"<}
    void animal1();

    本文引用地址:http://www.czjhyjcfj.com/article/201612/324420.htm

    };
    void animal::animal1 () //構(gòu)造函數(shù)
    {
    int box[3],i,sum=0; //sun記得賦初值
    cout<<"請輸入三個(gè)數(shù)"< for(i=0;i<3;i++)
    {
    cin>>box[i];
    sum=box[i]+sum;
    }
    cout<}
    int main()
    {
    animal sh;
    sh.animal1 ();
    return 0;
    }



    評論


    技術(shù)專區(qū)

    關(guān)閉
    主站蜘蛛池模板: 无极县| 双牌县| 太仆寺旗| 繁昌县| 镇安县| 安泽县| 宿松县| 中西区| 孝感市| 革吉县| 博客| 松桃| 澎湖县| 资讯 | 昆明市| 天峨县| 铜陵市| 类乌齐县| 定安县| 瑞安市| 龙山县| 长白| 北宁市| 修水县| 宝清县| 浦东新区| 新泰市| 全南县| 开封市| 崇州市| 临桂县| 治县。| 宜章县| 萍乡市| 黄陵县| 肥西县| 广汉市| 宝坻区| 佛冈县| 荣昌县| 图们市|