JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

destructor in c++ language , what is destructor in c++ explain in hindi with example program

what is destructor in c++ explain in hindi with example program , destructor in c++ language :-
इससे पहले के article मे , c++ language के सबसे महतवपूर्ण concept constructor को discuss किया है  | अब इस article मे c++ language के दुसरे महतवपूर्ण concept destructor को discuss किया था |
C++ destructor
जब किसि constructor को किसिस object को create करने के लिए किया जाता है तब किसी प्रोग्राम से किसी object की responsibility को ट्रैक किया जाता है | अतः प्रोग्राम किसी प्रोग्राम को आटोमेटिक call करता है जिसे destructor  कहते है | destructor का use किसी object को clear करने के लिए use किया जाता है | अतः इस destructor को useful application होता है |
जब किसी constructor new का use किसी object के लिए memory को allocate करने के लिए use किया जाता है तब destructor , delete command  को किसी object को डिलीट करने के लिएर किया जाता है | destructor का use किसी memory को free करने के लिए किया जाता है |
stock construtor का use किसी new क्कोम्मंद को use करना complusy नहीं होता है | इसलिए किसि stock destructor मे भी कोई भी task को perform नहीं किया जाता है |अतः complier destructor को  implicit declare नहीं किया जाता है | लेकिन destructor  को explicit declare किया जाता है तब इसका syntax निन्म होता है :
constructor की तरह destructor  का sepcial name होता है | इसे tilde operator (~) को use किया जाता है | जैसे stock destructor को ~stock से call किया जता है | constructor की तरह descructor की तरह कोई भी value return नहीं होती है | और इसका कोई भी declare type नहीं होता है | लेकिन constructor की तरह destructor मे कोई भी argument pass नहीं होता है | अतः इसका  syntax निन्म होता है :
~stock ();
stock()destructor  का केवल एक ही ड्यूटी होता है | इसका syntax निन्म होता है :-
stock :: ~stock ()
{
}
जब किसी destructor  को call किया जाता है तब इसका execution को निन्म code से पहचान जा सकता है :-
stock :: ~stock ()
{
cout<<“object delete !”;
}
जब किसी static object को create किया जाता है तब प्रोग्राम इस code मे allocate memory को आटोमेटिक terminate कर देता है |
जब किसी आटोमेटिक  class object को create किया जाता है तब प्रोग्राम इस destructor से   allocate memory को आटोमेटिक terminate कर देता है | जब class मे perform किये गये task को execute करने के बाद destructor allocate memory को डिलीट किया जाता है |
जब किसि object को new से create किया जाता है तब ये object heap memory और free store मे located होता है | और जब डिलीट command को use किया जाता ही तब destructor से allocate memory से डिलीट किया जाता है |
प्रोग्राम से temporary object को create किया जाता है | जो की कुछ sepecfic task को perform किया जाता है |
जाब class object expire हो जाता है तब destructor को आटोमेटिक call किया जाता है |
Stock management project का modify form :
इससे पहले के article मे discuss Stock management project मे केवल construtor को उससे किया जाता है लेकिन अब इस article मे construtor और destructor को use किया गया है | c++ language मे बहुत लम्बे code को store करने के लिए file format को useकिया जाता है | इसमें code को अलग लग file मे store किया जाता है |
हेडर file stock.h मे हेडर code को include किया जाता है | इसमें class की declartion और source code file जो की method की definition को hold करता है को hold करता है | इसके लिए सभीfile को ट्रैक easily किया जाता है |
stock.cpp मे class की definition को hold किया जाता है |
इसका code निन्म है :
stock.h
class stock
{
char company [50];
int share ;
double sharevalue ;
double total ;
void set_total (){total = share value * share ;}
public :
stick ();
void buy();
void sell();
void show();
void update ();
}
stock.cpp mai
#include<iostream>
#include<conio.h>
stock :: stock (const char * compnany , int n =0 , double price = 0.0 )
{
std :: strcpy ( name ,company,50 );
company[50]=’\0′;
if(n<0)
{
std::cerr<<“share can not be negetive “;
       << we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
share = n ;
share_price = price ;
total ();
}
stock :: ~stock ()
{
std :: cout<<“Stock Management Syatem Close “<<Bye ;
}
stock :: buy()
{
if(n<0)
{
std::cerr<<“share purchase can not be negetive “;
       << Please enter share more than ‘0’ “<<endl;
share = 0 ;
}
else
share += n ;
share_price = price ;
total ();
}
stock :: sell()
{
if(n<0)
{
std::cerr<<“share sell can not be negetive “;
       << Please enter share more than ‘0’ “<<endl;
share = 0 ;
}
else
share -= n ;
share_price = price ;
total ();
}
stock :: show()
{
cout<<“company Name :<<company ;
cout<<“share value  :”<<total ;
cout<<“share number :”<<sharevalue
}
Input File मे ,
इस file मे यूजर द्वारा input किये data को console screen पर display किया जाता है और data पर operation perform किया जाता है |इसका code main() function होता है | इसका code निन्म है :
main()
{
cout<<“using constructor for create object “;
stock company1 (“parth “,30 , 200);
company1.show();
stock company2(“meet “,50 , 100);
company2.show();
cout<<“assignment operator”;
company2= company1;
company2.show();
company1.show();
cou<<“using construtor to reset object”;
company2=stock (“Om”,200,200);
cout<<“revised stock”;
company2.show();
cout<<“Done !”;
}
}
इस article मे destructor को discuss किया है अब आगे के article मे destructor के advance method को discuss करेगे |
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