हिंदी माध्यम नोट्स
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
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
21 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
21 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
3 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
3 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago