हिंदी माध्यम नोट्स
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
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…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
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…
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…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…