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

सती रासो किसकी रचना है , 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
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