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

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