C++における関数リロードの例の詳細
1262 ワード
C++における関数リロードの例の詳細
関数の再ロード:
1、同じ名前で、基本的に同じ操作を行いますが、異なるパラメータのリストを使用します.2、関数は多態性を有する.3、コンパイラは呼び出し時のパラメータの個数とタイプによって、呼び出しリロード関数のどの定義を決定する.4、異なるデータセットに対して基本的に同じタスクを完了した関数のみを再ロードする.
関数リロードの利点
1、異なる関数名を使う必要がない2、コードの理解とデバッグに役立つ3、コードのメンテナンスが容易
次に、コードを直接入力します.
実行結果:
読書に感謝して、みんなを助けることができることを望んで、みんなの当駅に対する支持に感謝します!
関数の再ロード:
1、同じ名前で、基本的に同じ操作を行いますが、異なるパラメータのリストを使用します.2、関数は多態性を有する.3、コンパイラは呼び出し時のパラメータの個数とタイプによって、呼び出しリロード関数のどの定義を決定する.4、異なるデータセットに対して基本的に同じタスクを完了した関数のみを再ロードする.
関数リロードの利点
1、異なる関数名を使う必要がない2、コードの理解とデバッグに役立つ3、コードのメンテナンスが容易
次に、コードを直接入力します.
#include
using namespace std ;
void say_hello(void)
{
cout << "this is hello" << endl ;
}
//
void say_hello(int a = 100)
{
cout << "this is hotdog" << endl ;
}
int say_hello(double a )
{
cout << "this is hotpig:" << a << endl ;
}
//
int say_hello(int a, int b, int c)
{
cout << "a+b+c = " << a+b+c << endl ;
}
int main(void)
{
say_hello(100);
say_hello(11.11);
say_hello(1 , 2 , 3);
return 0 ;
}
実行結果:
this is hotdog
this is hotpig:11.11
a+b+c = 6
読書に感謝して、みんなを助けることができることを望んで、みんなの当駅に対する支持に感謝します!