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

Template (Explicit specialization) in c++ language with hindi explanation , source code

source code , Template (Explicit specialization) in c++ language with hindi explanation :-
इससे पहले के article मे specialization को discuss करेगे जो की function overload या function template के साथ जरुर read करना चाहिए जो की function overload प्रॉब्लम को और अच्छी तरह से समज सकते है |specialzation दो प्रकार का होता है :-

Explicit specialization
जब किसी struture को declare किया जाता है जैसे
struct employee
{
char name [60];
int salary ;
int floor ;
};
और अगर किसी दो struture के दो element मे swap करना होता है तब template को in operation के लिए use किया जा सकता है |
temp = a;
a=b;
b=temp;

इस template से swap operation को perform किया जासकता है | क्योकि c++ language मे struture के elements को swap किया जा सकता है | अगर template a का type employee struture होता है | अतः employee struture के element salary और floor को swap किया जासकता है \ लेकिन name को swap नहीं किया जासकता है |इसके लिए एक  नए swap function की जरुरत होती है | लेकिन swap function मे pass arguments सामान होता है | इसके लिए function template overload को use किया जासकता है | जिसमे function name और pass argument तो सामान है लेकिन उसमे perform किये गये operation अलग होता है |
इस तर ह के function को Explicit specialzation कहते है | जब complier को कोई sepecial definition मिलता है तब complier template को consider नहीं करता है इसके लिए declare किये गये Explicit specialzation function को perform करता है |
Explicit specialzation का form c++ मे time के साथ change होता है लेकिन इस article मे Explicit specialzation का current form को discuss करेगे | जिसे third generation Explicit specialzation कहते है |

Third Generation Explicit specialization
c++ language मे Third Generation Explicit specialzationके निन्म rules को discuss करेगे :-
1.किसी एक function के लिए Third Generation Explicit function , function template और non template function को use किया जा सकता अहि | जिसके लिए function overload होता है |
2.Third Generation Explicit specialzation function की definition और prototype template<> से पहले declare किया जाता है |
3.Third Generation Explicit specialzation function , regular template function को override कर देता है लेकिन regular function , दोनों ही function को override कर देता है |
इसके लिए निन्म उदाहरन होता है :-

#include<iostream.h>
#include<conio.h>
template <class any>
void swap ( any &a, any &b );
struct employee
{
char name [60];
int salary ;
int floor ;
};
template <> void swap <employee > (employee &e1 , employee &e2 );
void show (employee &e);
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;
employee e1 = {‘Parth’ , 30,000,12};
employee e2 = {‘Meet’ , 20,000,11 };
cout<<“Before Swap “;
show(e1);
show(e2);
cout<<“After swap using Array”;
swap(e1,e2 );
cout<< “Now :”
show(e1);
show(e2);
getch();
}
template< class any >
void swap ( any &a , any &b )
{
any temp ;
temp = a;
a=b;
b =  temp;
}
template <> void swap <employee > (employee &e1 , employee &e2 )
{
double t1 ;
int t2;
t1= e1.salry ;
e1.salary = e2 . salary ;
e2.slary = t1 ;
t2 = e1.floor ;
e1.floor = e2.floor ;
e2.floor = t2 ;
}
void show ( employee e)
{
cout<<“Emplooye name:”<<e.name ;
cout<<“salary :”<<e.salary ;
cout<<“Floor :”<<e.floor;
}

Earlier Approach of specialization
नीचे दिए गये code अभी complier के साथ मे execute नहीं होता है | लेकिन नीचे दिए गये code को भी discuss करना जरुरी है |इसका code होता है :
template <> void swap <employee > (employee &e1 , employee &e2 )
{
double t1 ;
int t2;
t1= e1.salry ;
e1.salary = e2 . salary ;
e2.slary = t1 ;
t2 = e1.floor ;
e1.floor = e2.floor ;
e2.floor = t2 ;
}
को
void swap (employee &e1 , employee  &e2)
replace करते है |

जब complier swap() function को call किया जाता है | तब दो प्रकार के function को generate किया जा सकता है | पहले method मे non template function को generate किया जा सकता है \ और दुसरे method मे template function को use किया जा सकता है | template facility मे non template function को use किया जा सकता है |
इस एप्रोच को बहुत कम ही complier मे use किक्या जा सकता है |
अतः
template <> void swap <employee > (employee &e1 , employee &e2 ) को current form मे use किया जाता है |
void swap<employee>(employee &e1 , employee &e2) को ओल्डर version मे use किया जा सकता है |
ओल्डर version मे template <> को use नहीं किया जा सकता है | लेकिन
नीचे दिए गये
template<> void swap<employee>(employee &e1 , employee &e2)
{
code
}
को
void swap ( employee &e1 , employee &e2 )
{
code UNCHAGED ;
}

इसा article मे, Third Generation Explicit specialzation को discuss किया है अब आगे के article मे template से संबदित कुछ और TERMS को discuss किया जाता है |

Sbistudy

Recent Posts

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

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

2 days ago

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

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

4 days ago

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

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

7 days ago

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

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

7 days ago

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

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

7 days 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