हिंदी माध्यम नोट्स
CLASS SCOPE in c++ language in hindi , class scope impermanent , example code
global : इस type के variable को पुरे code मे कही पर भी use किया जा सकता है |
local : इस type के variable को केवल define scope मे ही use किया जा सकता है |function name केवल global scope होता है इसका कभी भी local scope नहीं होता है | क्योकि function को कभी भी किसी भी जगह call किया जाता है | c++ लंगुअग एमई एक नए प्रकार के scope को define किया गया है | जिसे class scope कहते है इस article मे class scope को ही discuss करेगे |
class scope
class scope को class के अंडर define किये गय name पर लागु किया जाता है | अगर class scope को variable memeber के साथ use किया जाता है तब memeber variable को class data memeber कहते है और जब class scope को memeber function के साथ use किया जाता है तब memeber function को class function memeber कहते है | जिस भी member को class scope के साथ define किया जाता अहि use केवल class के अंदर ही use किया जा सकता है | इस प्रकार सामान memeber name को दो या दो से अधिक class मे define किया जा सकता है | क्योकि एक class memeber का scope तो class मे limit रहता है |
class scope impermanent
जब किसिस क्लास मे member function को define करने के लिए unadorned memeber name को use किया जाता है | इससे पहले के उदहारण मे sell () function मे set_total() को call किया जाता है | constructor name को call किया जाता है क्योकि इसका नाम class name के सामान होता है | इसके अलावा membership operator (.) या membership operator(->) और scope resolution operator (::) को use किया जाता है | इसके लिए code के typeपर निर्भर करता है | निन्म कोदेमै class scope को use किया गया है जिससे आप सभी को class scope implement करने के method को समजा जा सकता है :-
class ik
{
private :
int a;
public :
ik(int add= 12 )
{
a= add;
}
}
void dispaly ()const ;
}
void ik :: display ()
{
cout<<a<<endl;
}
int main()
{
ik*d = new ik ;
ik g = ik(56);
g.display();
d->display ();
getch();
}
इस code मे , variable a का scope class scope होता है | और इसके बाद function को define किया जाता है | जिसमे use द्वारा input किये गये data को variable a मे assign किया जाता है |
इसके बाद display () function को define किया जाता है जो की class ik का type का होता है | इसलिए class के variable ‘a’ को use किया जाता है |
उदाहरन 2
इस उदाहरन मे दो अलग अलग class को define किया गया है जिसमे number variable name को use किया गया है | इस number variable का scope class scope है इसलिए केवल class calculator मे use किया जाता है | और दुसरे class statics मे number[] array को define किया जाता है | जिससे टीम function मे implement किया जाता है |
#inclue<iostrem>
#include<conio>
using namespace std;
class calculator
{
private :
int a,b;
private :
void add(int a , int b );
void sub(int a , int b );
void mul(int a , int b );
void div(int a , int b );
void display( int a , int b )
{
cout<<“Addition is “<<add(a,b)<<endl;
cout<<“Subtraction is “<<sub(a,b)<<endl;
cout<<“Multipliaction is “<<mul(a,b)<<endl;
cout<<“Division is “<<div(a,b)<<endl;
} ; // close of class
calculator :: add(int a , int b ) {
return a+b;
}
calculator :: sub (int a , int b ) {
return a-b ;
}
calculator :: mul(int a , int b ) {
return a*b ;
}
calculator :: div(int a , int b ) {
return a/b ;
}
class satistic
{
int b [12];
satistic (int * num)
{
b = num ;
public ::
void avg ()
{
int sum = sum + b [i] ;
}
int avg = sum / 12 ;
cout<<“Avgerage : ” <<avg ;
}
void main()
{
int num1 , num2 ;
cout<<“enter number 1 :”<<endl;
cin>>num1 ;
cout<<“enter number 2 :”<<endl;
cin>>num2 ;
ca.display(num1 , num2) ;
int a[12];
cout<<“Enter data : “<<endl;
for(i=0 ; i<12 ; i ++)
{
cin>>a{i];
}
satistic.s();
s.avg(int * a );
getch();
}
इस code मे , दो class calculator और satistic को define किया गया है | जिसमे
class calculator मे , variable a और b को define किया गया है | और इसके अलावा चार function को define किया गया है | इस function मे variable name a और b को use किया जाता है |
class satistic मे , एक और variable a को उसी किया गया जो की class calculator मे define किया गया है | अतः class scope का सबसे बड़ा advantage निन्म होता है | की एक name जिसे किसी class मे define किया गया है उसे किसी और class मे define किया जाता है |
इस article मे , class scope को discuss किया गया है इसके बाद के article मे , abstract data type को discuss करेगे |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
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 ,…