sdut 3-3 建構函式的調用(進階),sdut3-3

來源:互聯網
上載者:User

sdut 3-3 建構函式的調用(進階),sdut3-3

3-3 建構函式的調用(進階) Time Limit: 1000MS Memory limit: 65536K 題目描述

通過本題目的練習可以掌握建立普通對象、建立對象數組和動態建立和析構對象時調用建構函式和解構函式的時機;

要求建立一個類A;類中僅包含建構函式和解構函式,按照程式的輸出寫出類的定義和主函數main中的代碼。

輸入 

無

輸出 

輸出共有11行資料,分別如樣本輸出所示

樣本輸入
無
樣本輸出
----begin main---constructing an object of Aconstructing an object of ADestructing an object of A*******constructing an object of Aconstructing an object of A----end main---Destructing an object of ADestructing an object of ADestructing an object of A
提示 來源 黃晶晶樣本程式

#include <iostream>using namespace std;class A{public :    A()//建構函式    {        cout <<"constructing an object of A"<< endl;    }    ~A()//解構函式    {        cout <<"Destructing an object of A"<< endl;    }};int main(){    cout << "----begin main---" << endl;    A a;    A *b;//定義一個指向A類對象的指標變數b    b=new A;//在b中存放了建立對象的起始地址    delete b;//釋放b指向的記憶體空間    cout <<"*******"<< endl;    A c;    A d;    cout <<"----end main---"<< endl;    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.