JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

Function Overload example in c++ language , what is Function overload source code with explanation

what is Function overload source code with explanation , Function Overload example in c++ language :-
इस article मे , function overload और function template को discuss करेगे | अतः इस article को जरुर अच्छी तरह से read करे जिससे आप सभी को c++ language के महत्वपूर्ण topic को समज सकते है |Function overload
c++ language मे function polymorphism सबसे महतवपूर्ण capablity होती है | इसमें function मे pass किये गये arguuments की सख्या function definition मे declare किये गये arguments से कम या ज्यादा होता है | इस condition को function polymorphism कहते है | यस जब दो या दो से अधिक function का नाम समाए होता है तब इसे function polymorphism  कहते है |

Function template
c++ language मे function template के concept को introduce किया है | function template एक generic function description है | generic function description मे function के type को define किया जाता है | जसिसे int या double |
किसी function template मे argument को pass किया जाता है तब complier एक generic function description को generate किया जाता है |इस programming को generic programming कहते है | अगर function मे argument के type को define किया जाता है जब इसे paramerized types कहते है |

Generic Programming
नीचे दी गये प्रोग्राम मे swap function को consider किया गया है | जिसमे दो integer value को swap किया जाता है | इसके अलावा swap function को double type के साथ भी discuss किया जाता है | लेकिन अगर char को swap किया जाता है तब इस function को भी use किया जाता है | लेकिन एक function को अलगअलग दत्त type को use किया जाता है | तब इस function से error होता है | इस error को change करने के लिए आप by hand भी change किया जाता है | तो ये method काफी time consume होता है | इस method के अलावा global search and replace method को use किया जाता है | उद्धरण के लिए
int a;
short int;

double case मे ,
double a ;
short double;

c++ language मे इस convert करने केलिए function template को use ककिया जाता है | जैसे
template <class any >
void swap ( any a , any b )
{
any temp ;
temp = a;
a=b;
b =  temp;
}

इस method मे function template को set किया है | इस function template का नाम any है | template और class का declare करना सामान होता है | लेकिन इसमें keyword से differentia किया जता है | उसके बाद function template को {} मे define किया जाता है | type name template को define नहीं किया जाता है | इसके लिए कई प्रोग्रामर ‘T’ को ज्यादा use करते है | इसके अलावा function template मे function को define नहीं किया जाता है | इस function template से function template , complier को define करते है किस तरह से function को define किया जाता है |
जैसे अगर किसी  दो integer को swap function को define किया जाता है इस function मे int को any से replace किया जाता है |  और  जैसे अगर किसी  दो double को swap function को define किया जाता है इस function मे double को any से replace किया जाता है |

c++ language मे अभी अभी type name को class की जगह use किया जाता है | इसका syntax निन्म होता है :-
template < typename any >
void swap ( any a , any b )
{
any temp ;
temp = a;
a=b;
b =  temp;
}

function template से complier को check किया जाता है | सबसे पहले function को call किया जाता है | तब सबसे पहले function मे pass argument को र्त्पे को पता लगाया जाता है इसके बाद उस type के function को generate किया जाता है |

Source Code
#include<iostream.h>
#include<conio.h>
template <class any>
void swap ( any &a , any &b);
void main()
{
using namespce std;
int a = 10 ;
int b = 120;
cout<<“Before Swap “;
cout<<“a :”<<a<<“b :”<<b;
cout<<“After swap using integer “;
swap(a,b);
cout<< “Now :”
cout<<“a :”<<a<<“b :”<<b;
double a = 10.40 ;
double b = 12.56 ;
cout<<“Before Swap “;
cout<<“a :”<<a<<“b :”<<b;
cout<<“After swap using double “;
swap(a,b);
cout<< “Now :”
cout<<“a :”<<a<<“b :”<<b;
getch();
}
template< class any >
void swap ( any a , any b )
{
any temp ;
temp = a;
a=b;
b =  temp;
}

जब पहली swap () function को call किया जाता है तब निन्म function को generate किया जाता है जिसमे any को integer से replace किया जाता है | :-
void swap ( int a , int b )
{
int temp ;
temp = a;
a=b;
b =  temp;
}

जब दुसरे swap () function को call किया जाता है तब निन्म function को generate किया जाता है जिसमे any को double से replace किया जाता है | :-
void swap ( double a , double b )
{
double temp ;
temp = a;
a=b;
b =  temp;
}

इसका आउटपुट होगा :
Before Swap
a : 10 b : 20
After swap using integer
a : 20 b : 10
Before Swap
a : 10.40  b : 20.56
After swap using integer
a : 20.56  b : 10.40

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

Sbistudy

Recent Posts

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

1 day ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

3 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

5 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

5 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

5 days ago

FOURIER SERIES OF SAWTOOTH WAVE in hindi आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित

आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित FOURIER SERIES OF SAWTOOTH WAVE in…

1 week ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now