Cpp クラス 仮想関数 新しいページはコチラ
提供: yonewiki
(→クラス 仮想関数) |
(→クラス 仮想関数) |
||
| 81行: | 81行: | ||
</syntaxhighlight2> | </syntaxhighlight2> | ||
| + | これで以下のようなメイン関数を作って | ||
| + | |||
| + | <span style="color: #ffffff; background-color: #555555; padding: 0px 5px 0px 5px; display: inline-block;">cpp <span>(</span>メイン関数 InheritanceMain.cpp<span>)</span><!-- padding 上 右 下 左--> | ||
| + | <syntaxhighlight2 lang="cpp" line start=1000> | ||
| + | #include "pch.h" | ||
| + | #include "BaseInheritance.h" | ||
| + | #include "DeriveInheritance.h" | ||
| + | #include "DeriveArrInheritance.h" | ||
| + | #include "DeriveDiscountInheritance.h" | ||
| + | |||
| + | |||
| + | |||
| + | int main() { | ||
| + | |||
| + | CBaseInheritance objCBaseIneritance(1900, 12); | ||
| + | objCBaseIneritance.mfVirtual_vDispValue(); | ||
| + | |||
| + | return 0; | ||
| + | |||
| + | } | ||
| + | </syntaxhighlight2> | ||
| + | |||
| + | 実行すると | ||
| + | |||
| + | <span style="color: #ffffff; background-color: #555555; padding: 0px 5px 0px 5px; display: inline-block;">実行結果<!-- padding 上 右 下 左--> | ||
| + | <syntaxhighlight2 lang="text" line start=1100> | ||
| + | Constructor:CBaseInheritance(int,int) | ||
| + | Constructor:CDriveInheritance(int,int) | ||
| + | BaseMoney=34800, total=35700 | ||
| + | Constructor:CBaseInheritance(int,int) | ||
| + | Constructer:CDeriveArrInheritance(int,int,int*,int) | ||
| + | BaseMoney=34800, total=36520 | ||
| + | Constructor:CBaseInheritance(int,int) | ||
| + | Constructer:CDeriveDiscountInheritance(int,int,double) | ||
| + | BaseMoney=46800, total=23400 | ||
| + | Destructor:~CBaseInheritance() | ||
| + | </syntaxhighlight2> | ||
[[C PlusPlus#C++からの技術|C++]]に戻る | [[C PlusPlus#C++からの技術|C++]]に戻る | ||