JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

c++ : Function Template Overload in hindi , what is Function Template Overload examples

what is Function Template Overload examples , c++ : Function Template Overload in hindi :-
जब किसी function template को use किया जाता है इसके द्वारा function overload की प्रॉब्लम को solve किया जाता है | जब किसि function को अलग अलग type को use किया जाता है | तब एक अलोगोरिथ्म को इन सभी type की use किया जाता है | इस प्रॉब्लम को solve करने के लिए template overload को discuss करेगे |
function template overload
function template मी overload करने के लिए अलग अलग function signature को use किया जता है | जब swap function को array के साथ use करने के लिए function template any को ही use किया जाता है | लेकिन  इस  function template मे array को pass किया जाता है | क्योकि जब function swap को array के लिए call किया जाता है तब swap function की डेफिनिशन को array के लिए declare किया जाता है |
इसका source code निन्म है :
#include<iostream.h>
#include<conio.h>
template <class any>
void swap ( any *a , any *b int n );
void show (int a []);
const int size 8;
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[size] = {12,23,32,12,12,45,65,102};
double b [size]= {13,24,33,13,13,46,67,104};
cout<<“Before Swap “;
cout<<“Array a :”<<show(a);
cout<<“Array b :”<<show(b);
cout<<“After swap using Array”;
swap(a,b , size );
cout<< “Now :”
cout<<“Array a :”<<show(a);
cout<<“Array b :”<<show(b);
getch();
}
template< class any >
void swap ( any &a , any &b , int n  )
{
any temp ;
for(i =0 ; i< size ; i ++ )
{
temp = a;
a=b;
b =  temp;
}
}
void show (int a [])
{
using namespace std ;
for(int i = 0 ; i < 8 ; i ++)
{
cout<<a[i];
}
जब इस function swap को integer के लिए call किया जता है तब इस function मे integer को pass किया जाता है | लेकिन जब इस function को array के लिए use किया जाता है तब इस function मे pass argument मे argument को pass किया जाता है |
जब किसी प्रोग्राम मे function template , function overload और function template overload होता है तब एक perfect methodology कलो use किया जाना चाहिए जो की function की डेफिनिशन और calling प्रोसेस को define करता है | इस प्रोसेस को overload resolution कहते है |
इस प्रोसेस मे निन्म step होता है :
1.सबसे पहले function related information को gather करता है | इसमें  functions , function templates जिनकी name सामान होता है की detail include होती है |
2.function related information मे vailable function की detail hold करता है | इस ffunction मे argument की सख्या  calling function से equal होती है |
3. जब किसी बेस्ट vailable function को calcualte किया जाता है | और अगर id function को call किया जाता है तब error आ जाती है |
इन पॉइंट्स को अच्छी तरह से समज के लिए क्निन्म उदाहरन को discuss किया जाता है  :-
अगर किसी function dec () को call किया जाता है | जब किसी function को call किया जाता है :
void dec(int);
void dec(float , float = 3 );
void dec(char);
void  *dec (char * );
char dec(const char & );
template<class T > void dec (const T & );
template <class T > void dec (const T *);
ये सभी function का signature है | जो की return type को नहीं बल्कि signature को भी define करता है |
function prototype 4 और 8 viable function नहीं है क्योकि integral type को implicity मे convert नहीं किया जासकता है |
इसके अलावा बाकि के template से char type को generate किया जाता है | ये सभी viable function है
complier किसी function के लिए  बेस्ट viable template को choose किया जा सकता है | conversion से किसी call function को viable function template से match किया जाता है | इसके लिए निन्म rules होते है :
1.exact match के साथ regular function   , template को overload करता है |
2.Conversion को promotion से perform करता है | (automatic conversion of char and short into int ).
3.Conversion को  standaradconversion से perform करता है | (  conversion of char and short into int ).
function 1 , function 2 से better होता है क्योकि char to int [promotion] conversion होता है | और char to float standarad conversion होता है |
function 3 , function 5 और function 6 , function 1 और function 2 से better होता है क्योकि इनका exact match होता है |
इससे आगे के article मे , matching को discuss करेगे जिसमे किसी function के लिए बेस्ट template को find करने के rules को discuss करेगे | और function matching के basic को भी discuss भी करेगे
Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month 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