FUNCTION OVERLOAD in c++ language , what is Function Polymorphism in hindi

what is Function Polymorphism in hindi , FUNCTION OVERLOAD in c++ language :-

function polymorphism , c++ language मे add की capablity मे से एक है | इस article मे function overloading को discuss करेगे जो की c++ language मे सबसे महत्व पूर्ण capablity मे से एक है |

Function Polymorphism

जब किसी function मे pass किये  गये argument की सख्या default arguments से ज्यादा होती है उसे function polymorphism कहते है | function polymorphism को function overload भी कहते है |जब किसी दो या दो से ज्यादा  functions का एक नाम होता है तब use function polymorphism कहते है | polymorphism का मतलब है multiple forms| इसलिए function polymorphism का मतलब function का multiple forms |

function overload का मतलब है एक या एक से ज्यादा function को किसी एक function से attach करना होना होता है | function overload की working को समजना  थोडा मुश्किल होता है  | लेकिन जब किसी एक class के function को declare करने के लिए function ओवरलोडिंग को use किया जाता है |function overload मे function का नाम same होता है लेकिन उसमे pass किये argument अलग अलग होते है |

function overload मे function के argument मुख्य होते है |इन argument को function signature कहते है |जब कोई दो function मे argument के type और सख्यां सामान होती है तब दोनों function का signature समान होता है | और उस condition मे function के नाम का कोई effect नहीं पड़ता है | signature को change करने के लिए  उन function मे pass किये जाने वाले arguments की सख्या और type का role रहता है |

उदाहरन के लिए :

void print(char *s, int width );

void print (int a, int b);

void print (long a, int width);

void print (const char *s);

void print(double a, int width);

जब यूजर  किसी  print() function को use किया  जाता है complier print मे pass किये गये argument को print prototype से match करता है | और उस function को call किया जाता है |

जब किसी function overload को use किया जाता है function call statement मे pass किये गये argument को ध्यानपूवर्क use किया जाता है |इसके लिए निन्म उदाहरनो को discuss करेगे |

#include<iostream.h>

#include<conio.h>

void print(int , int );

void print(char , char );

void print ( double , double );

void print(long double lond double);

void main()

{

int a,b;

char c,d;

long double d,e;

double f,g;

cout<<“Enter integer Value :”<<endl;

cin>>a;

cin>>b;

cout<<“Enter characetr Value :”<<endl;

cin>>c;

cin>>d;

cout<<“Enter double Value :”<<endl;

cin>>f;

cin>>g;

cout<<“Enter long double Value :”<<endl;

cin>>d;

cin>>e;

print(a,b);

print(c,d);

print(f,g);

print(d,e);

getch();

}

void print(int u , int v )

{

cout<<u<<endl;

cout<<“************”;

cout<<v<<endl;

}

void print(char u, char v )

{

cout<<u<<endl;

cout<<“************”;

cout<<v<<endl;

}

void print ( double u , double v )

{

cout<<u<<endl;

cout<<“************”;

cout<<v<<endl;

}

void print(long double u ,lond double v)

{

cout<<u<<endl;

cout<<“************”;

cout<<v<<endl;

}

इस उदहारण मे , print() function को use किया जाता है | लेकिन

void print(int u , int v ) मे pass किये गये argument integer है |

void print(char u, char v ) मे pass किये गये argument character है |

void print ( double u , double v ) मे pass किये गये argument double है |

void print(long double u ,lond double v) मे pass किये गये argument long double है |

Function Overload को use कब किया जाता है :

function overload को use किया जाता है लेकिन इसका ज्यादा use नहीं किया जाता है |function overload को same task के लिए बनाया जाता है लेकिन उस function मे pass किये गये arguments का type अलग अलग होता है | 

इसके अलावा निन्म उदाहरानो को discuss करेगे :

#include<iostream.h>

#include<conio.h>

void *left(const char *s , int n =1 );

void main()

{

using namespace std;

char *trip = “jaipur”;

unsigned long n = 1234567;

int i ;

char *temp;

for(i=0;i<10;i++)

{

cout<<left(n,i)<<endl;

temp = left(trip,i);

cout<<temp<<endl;

delete[]temp;

}

getch();

}

uncsigned long left ( unsigned long num , unsigned c)

{

undsigned digit = 1;

unsigned long n= num;

if(cv==0||num= =0)

{

return 0;

while(n/=10)

digit++;

if(digit>c)

{

c=digit-c;

while(c–)

num=num/10;

return num;

}

else

return num ;

}

char *left ( const char*st,int n)

{

if(n<0)

n=0;

char *p = nechar [n+1];

for(i=0;i<n&&s[i];i++)

{

p[i]=s[i];

while(i<=n)

{

p[i++]=”\0″;

return p;

}

}

इस उदहारण मे , left() function को use किया गया है जिसमे pointer को return किया जाता है जो की string के first n character को hold करता है | इसकेअलावा left() मे integer की फिरस्त डिजिट को return किया जाता है | integer function string function से थोडा मुश्किल होता है | और  string मे chracter को अक्र्रय की तरह store किया जाता है लेकिन number मे loop चलाया जाता है number की डिजिट को find करने के लिए | 

इस loop मे , number को 10 से divid किया जाता है जब भी किसी number को 10 से डिवाइड किया जाता है इसका remainder number का last डिजिट होता है और इसके बाद इस division से प्राप्त qusent को number से update किया जाता है |  

इसका आउटपुट निन्म होगा :

1

j

12

ja

123

jai

1234

jaip

12345

jaipu

123456

jaipur

1234567

jaipur!

इस article मे function overload को discuss किया है अब आगे के article मे function template को discuss करेगे |