10、11週目-プログラムを読む(1)
795 ワード
問題およびコード:
運転結果:CAEFBD
知識ポイントのまとめ:
構造関数、先に呼び出された後析構造.順序が逆だ.
/*
*Copyright (c) 2016,
*All rights reserved.
* :
* :
* : 2016 5 10
* : v1.0
*
* :
* :
* :
*/
#include <iostream>
using namespace std;
class Data
{
public:
Data(int i):x(i){cout<<"A";}
~Data(){ cout<<"B";}
private:
int x;
};
class Base
{
public:
Base(int i):b1(i){cout<<"C";}
~Base(){ cout<<"D";}
private:
int b1;
};
class Derived:public Base
{
public:
Derived (int i,int j):Base(i),d1(j){
cout<<"E";
}
~Derived(){cout<<"F";}
private:
Data d1;
};
int main()
{
Derived obj(1,2);
return 0;
}
運転結果:CAEFBD
知識ポイントのまとめ:
構造関数、先に呼び出された後析構造.順序が逆だ.