JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

Declaring of C++ constructors , Use of constructors , exam program source code in hindi

इससे पहले के article मे , constructor को discuss किया जाता है | इससे पहले के article मे constructor के syntax और declare करने को discuss किया जाता है |
Declaring of C++ constructors
constructors को declare करने के लिए जिस functio age के लिए constructors को declare किया जता जाता है उसमे pass किये जाने वाले argument को constructors के लिए use किया जासकता है | उदहारण के लिए persoage constructorsमे pass किये गये argument की सख्या तीन होती है | क्योकि यूजर द्वारा केवल तीन value को लिए जाता है |  इसका syntax निन्म है :
persoage  (const char * name , int age  =0 , double salary  = 0.0 )
इस  constructors
पहला argument एक string का pointer है जिसमे persoage का name member से initial किया जाता है |
age : ये integer type variable है जिसमे persoage के age  को initail किया जाता है |
salary : ये double type variable है जिसमे persoage की salary को initail किया जाता है |
Use of constructors
c++ language मे , किसि object को initial करने क लिए दो method को use किया जाता है | दोनों ही method मे object को constructor से initial करने के लिए दो method को use किया जाता है |
सबसे पहले constructor को  explicit call किया जाता है |
persoage p = persoage  ( “parth” , 23 , 20,000 );
इस उदहारण से :
persoage object p के member variable name मे parth को initail किया जाता है |
persoage object p के member variable age  मे 23 को initail किया जाता है |
persoage object p के member variable salary मे 20,000 को initail किया जाता है |
दुसरे method मे constructor को implicit call किया जाता है | इसका syntax निन्म होता है :
persoage p( “meet” , 26 , 28,000 );
इस उदहारण से :
persoage object p के member variable name मे  meet को initial किया जाता है |
persoage object p के member variable age  मे 26 को initial किया जाता है |
persoage object p के member variable salary मे 23,000 को initial किया जाता है |
explicit constructor का format implicit constructor से complex होता है |
c++ language मे जब किसी c++ class को use किया जाता है तब c++ constructor को use किया जाता है |  जब किसी new operator का use किसी नए memory एलोकेशन को allocate करने के लिए use किया जाता है  तस्ब constructor को use किया जाता है |
persoage *p = new persoage  ( “parth” , 23 , 20,000 );
इस statement से persoage object को create किया जाता है जिसमे value को constructor के argument से initial किया जाता है | इस memory allocation से allocate memory space के address को pointer variable p मे assign किया जाता है | object का name नहीं होता है उसके pointer variable इस memory allocatioage को manage करने के लिए use किया जाता है |
constructor को किसी दुसरे class मे use करने के लिए दुसरे form को use किया जाता है |  कसी object को method को use करने के लिए use किया जासकता है | जैसे persoage मे show () एक functioage है तब इसे invoke करने के लिए किया जाता है:-
p.show();
Default Constructor
Default Constructor एक एस Constructor है जिसे किसी object को initial करने के लिए use किया जाता है | और इस Constructor को exciplit call नहीं किया जाता है | नीचे दिए उदाहरन मे  Constructor को use किया जाता है  जिसे class object को declare करने के लिए किया जाता है |
persoage p;
इस statement को use किया जाता है इसे Constructor को declare किये बिना object को use किया जाता है | c++ मे default Constructor को आटोमेटिक supllies किया जाता है |
जब किसि Constructor को explicit declare किया जाता है तब इस method को use नहीं किया जाता है | किसी persoage classमे , default Constructor को use किया जाता है :-
persoage :: person()
{
}
इस method के बाद persoage object को create किया जाता है लेकिन इस method मे member कोunintail किया जाता है | जिसे
int a;
किसी default Constructor को use करना complex होता है |किसी Constructor को define नहीं किया जाता है लेकिन जब किसी Constructor को declare किया जाता है तब default Constructor को use किया जाता है | जब किसी noage default Constructor को use किया जाता है तब  default constructor को use नहीं किया जाता है |persoage p; से error message आ जाता है |
Constructor का उदाहरन :
persoage :: persoage (const char * employee  , int age =0 , double salary  = 0.0 )
{
std :: strcpy ( name ,employee ,50 );
name [50]=’\0′;
if(n<0)
{
std::cerr<<” age इस not negative”;
       << we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
age = age ;
salary = salary ;
total ();
}
अगर इस उदाहरन को defualt Constructor को use किया जाता है तब इसका निन्म code होगा :-
persoage :: persoage ()
{
std :: strcpy ( name ,employee ,50 );
name [50]=’\0′;
if(n<0)
{
std::cerr<<” age is not negative”;
       << we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
age = age ;
salary = salary ;
total ();
}
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