हिंदी माध्यम नोट्स
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 भी करेगे
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
2 weeks ago
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
2 weeks ago
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
2 weeks ago
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
2 weeks ago
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
2 weeks ago
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…
2 weeks ago