Cpp クラス 継承 新しいページはコチラ

提供: yonewiki
移動: 案内, 検索
(クラス 継承)
(クラス 継承)
139行: 139行:
  
 
=メンバ関数の利用用途=
 
=メンバ関数の利用用途=
*m_fvDeriveDispValue():派生した方法での合計金額の中身を知るための関数
+
*'''m_fvDeriveDispValue()''':派生した方法での合計金額の中身を知るための関数
*m_fiDeriveSumMoney(): 合計金額を取り出す関数
+
*'''m_fiDeriveSumMoney()''': 合計金額を取り出す関数
  
 
 という感じです。
 
 という感じです。
190行: 190行:
 
<syntaxhighlight2 lang="cpp" line start=600>
 
<syntaxhighlight2 lang="cpp" line start=600>
 
#include <cstdio>
 
#include <cstdio>
#include "BaseInheritance.h"
 
 
#include "DeriveInheritance.h"
 
#include "DeriveInheritance.h"
  
 
int main() {
 
int main() {
//  CBaseInheritance objCBaseInheritance(3900, 12);
 
//  objCBaseInheritance.m_fvBaseDispValue();
 
  
 
     CDeriveInheritance objCDeriveInheritance(3900, 12, 600);
 
     CDeriveInheritance objCDeriveInheritance(3900, 12, 600);
204行: 201行:
 
</syntaxhighlight2>
 
</syntaxhighlight2>
  
 +
 +
 とすると、実行結果は
 +
 +
<span style="color: #ffffff; background-color: #555555; padding: 0px 5px 0px 5px; display: inline-block;">処理結果 </span><!-- padding 上 右 下 左-->
 +
<syntaxhighlight2 lang="text" line start = 700>
 +
Constructor:CBaseInheritance()
 +
Constructer:CDeriveInheritance(int,int,int)
 +
DeriveMoney=47400
 +
Destructer:~CDeriveInheritance()
 +
Destructor:~CBaseInheritance()
 +
</syntaxhighlight2>
 +
 +
 +
 のようになります。派生クラスを作成すると、基底のコンストラクタ引数無しの後に派生のコンストラクタ引数(int, int, int)が呼ばれて、メイン関数から、派生クラスの中身を表示させる命令を実行したあと、メイン関数がおわろうとする手前で、派生クラスのデストラクタが呼ばれて、基底クラスのデストラクタが呼ばれて終わっていることがわかります。
 +
 +
 +
 派生クラスを生成させたときの引数の数が一致するものがないときは基底クラスはでは、何もないコンストラクタが呼ばれます。
  
  
 
[[C PlusPlus#C++からの技術|C++]]に戻る
 
[[C PlusPlus#C++からの技術|C++]]に戻る

2020年7月14日 (火) 00:00時点における版



個人用ツール
名前空間

変種
操作
案内
ツールボックス