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

This Pointer in c++ language , what is type of this pointer in c++ in hindi , example source code program

example source code program , what is type of this pointer in c++ in hindi  , This Pointer in c++ language :-
इससे पहले के article मे , constructor और destructor को discuss किया है अब इस article मे this pointer को discuss करेगे जो की c++ मे constructor और destructor की तरह important होता है |
this pointer
stock management code मे और भी एडवांसमेंट हो सकता है और वो एडवांसमेंट this pointer से होता है | प्रत्येक class member function किसी एक object से associate होता है | लेकिन किसी एक method को दो अलग अलग object के साथ use किया जाता है तब c++ this pointer को उस किया जाता है |
Need of this pointer
stock class declaration को class data को display किया जाता है | show() function मे total को use किया जाता  है | और इस variable को use करने के लिए inline function को use किक्या जाता है | या इसके method से stored data को डायरेक्ट access किया जा सकता है  इसका कपड़े निन्म है :
class stock
{
private :
char company [50];
int share ;
double sharevalue ;
double total ;
double total ;
public :
void total (){ return total = share value * share;}
stick ();
void buy();
void sell();
void show();
void update ();
};
इस code मे , total variable से allocate memory को function total डायरेक्ट access कर सकता है | और इसलिए variable total की value को access करने के लिए  total method function को use किया जाता है | लेकिन class मे define member function total () से total variable को reset करने की facility नहीं होती है |
जब इस class मे एक और function greator() को add किया जाता है जो की ये पता लगता है की कोनसा शेयर की value highest है | इस function से this pointer को use किया जा सकता है | इस member function को define करने के लिए निन्म तरीके आपनाया जाता अहि की
दो object मे से reference को return किया जाता है और इसमें से greater value को return किया जाता है |  इस approach मे निन्म प्रॉब्लम निकल कर आती  है :-
1.किसी सदो object के एक member function के value को किस तरह से compare किया जाता है | उदाहरन के लिए greator() को use किया जाता ही | stock1.greator() से stock1 के data को access किया जाता है  | और stock2.greator () मे stock2 के data को use किया जाता है | जब in दोनों object को compare किया जता है तब दुसरे object को एक argument की त्राग pass किया जाता है | और इसके लोए reference method को use किया जाता है | इसलिए greator() मे const stock2 & को pass किया जाता है |
इस method मे एक object को implicit और explicit use किया जाता है | इस method मे से इन दोनों object मे से एक object का reference return होता है | const का use ये define करने के लिए किया जाता है की explicit object के memory address को constant हो और इसे change नहीं किया जा सकता है | और दोनों कही object का return type const होता है इसलिए इस method function का return type भी const होता है |
अतः अगर stock class के object stock1 और stock 2 को compare करना हो तो तब stock1 के function method greator() मे stock2 को pass किया जाता है इसक syntax निन्म होता है :
top = stock1.greator(stock2);
top = stock2.greator(stock1);
पहले syntax मे , stock1 को implicit और stock2 object को explicit access किया जाता है | और दुसरे  syntax मे , stock2 को implicit और stock1 object को explicit access किया जाता है |
और method function greator() का के निन्म होगा :
const stock & stock1 :: greator(const stock & stock2  )
{
if(total > stock2.total)
{
return total;
}
return stock2.total ;
}
इस code मे total object stock1 का data है और stock2.total का use stock2 के data को access किया जाता है | और code के execute किया जाता है तब इसमें से जिस भी object के variable total की value greater होगी वो return होगी | और नहीं ये member function जिस भी object से associate होता है उसकी value को return करता है | जब top = stock1.greator(stock2); को call किया जाता है तब इसका stock2 , stock का reference है लेकिन stock1 से  alias नहीं है |
इस प्रॉब्लम को solve करने के लिए this pointer को use किया जाता है | this pointerउस object को point करता है जो की member function को invoke करता है | top = stock1.greator(stock2);  मे this pointer stock1 object को point करता है क्योकि stock1 मे से member function को call किया जाता है |
top = stock2.greator(stock1); this pointer stock2 object को point करता है क्योकि stock2 मे से member function को call किया जाता है | this pointer को shorthand operator के साथ भी use किया जा सकता है | इसका syntax निन्म होता है :-
this->total ;
और उपर वाले code मे मॉडिफिकेशन निन्म होता है :-
const stock & stock1 :: greator(const stock & stock2  )
{
if(total > stock2.total)
{
return total;
}
return *this  ;
}
this pointer object के address को होड़ करता है और *this से इस pointer variable की value को use किया जाता है |इसका उदाहरन निन्म है :-
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 ();
const stock & stock :: greator(const stock & stock  )const ;
}
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
}
const stock & stock1 :: greator(const stock & stock2  )
{
if(total > stock2.total)
{
return total;
}
return *this  ;
}
Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

39 mins ago

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

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

3 days ago

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

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

5 days ago

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

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

1 week ago

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

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

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