हिंदी माध्यम नोट्स
c++ : namespace ( Advance ) with program example in hindi explanation , what is namespace in advance level
namespace को nested भी किया सकता है | इसका मतलब है की एक namespace के अन्दर दुसरे namespace को declare किया जासकता है | उदहारण के लिए :
namespace math
{
namespace add
{
int a;
int b;
}
namespace sub{
int a;
int b;
}
int *output;
}
इस उदहारण मे namespace math मे दो और namespace को declare किया गया है | namespace math मे add और sub namespace है | जिसमे दो – दो variable को declare किया गया है | इसके अलावा namespace math मे pointer variable output को declare किया गया है | जिसका use आउटपुट को hold करने में किया जाता है |
हम ये देख सकते है namespace add और sub दोनों मे declare variable का नाम सामान है अगर इन variable को use करने होता है तब using directive method को use किया जाता है |
इसका स्यन्त्रक्स निन्म होता है :
using namespace math :: add;
using namespace math :: sub ;जब namespace add के name a को use करने होता है तब इसका syntax नार्मल namespace की तरह होता है |
Feature 2 :
using directive और using declartion को किसी namespace के अन्दर भी use किया जा सकता है | उदाहरण के लिए :
namespace calculator
{
namespace div{
int c, d;
}
using namespace math ;
using google :: g;
using std::cout;
using std ::cin ;
namespace mul {
int e,f;
}
}
इस namespace मे calculatorके basic चार operations के variable के नाम को declare किया गया है | इसमें div और mul दो नए namespace है | लेकिन math जो की पहले declare कर चुके है | इसे केवल इस namespace मे add किया गया है | इन सभी को acess करने method निन्म है :
जब google namespace के variable name g को access करने होता है तब consider करते है की variable name g calculator का भाग है तब इसे access करने का syntax निन्म होगा :
std :: cin >> calculator :: g;
इसके अलावा g अभी भी google का पार्ट है इसलिए निन्म syntax को use किया जा सकता है :
cout<<google :: g;
local variable conflict को बचने के लिए निन्म syntax use किया जाता है :-\
using namespace calculator ;
cin>>g;
using directive को use किया जा सकता है | क्योकि using directive transtive. transtive का मतलब है की जब कोई operation A operation B और B operation C perform होता है तब indirect way मे A operation C perform होता है |
इसका मतलब है जब हम using namespace calculator ;को declare किया जाता अहि तब using namespace calculator google और using using namespace mul और using namespace math स्वत ही declare हो जाता है |
Feature 3 :
दो या दो अधिक namespace के बीच alias किया जा सकता है | इसका उदाहरन निन्म होता है :
namespace book
{
int price ;
string book _ name ;
string author ;
int year ;
}
namespace shop
{
int shop_number ;
string address ;
string name ;
}
जब namespace book और shop को alias किया जाता है | तब निन्म syntax को use किया जाता है :
namespace shop = book ;
इस feature का use nested namespace से अच्छा है क्योकि इसमें namespace को बार बार declare नहीं करना पड़ता है साथ ही reader को प्रोग्राम को read करना असना हो जाता है |
feature 4 : using directive VS using declartion
difference 1 : using directive माई कीई से किसी एक namespace के सभी name को इम्पोर्ट किया जाता है | using declartion से किसी केवल एक name को access कर सकते है |
difference 2 : दोनों method को use mass scope resolution operator को use किया जाता है |
जब using declartion method को use use किया जाता है तब namespace को जिस location मे declare किया जाता है उसी location या function मे use किया जा सकता है |लेकिन जब कोई name already function मे declare है तब using declartion का use उस variable name को access करने में नहीं किया जाता सकता है |
जब using directive method को use किया जाता है तब name resolution execute होइता जब namespace का name को declare किया जाता है या name space को declare किया जाता है |
उदाहरन के लिए
global namespace को use करने के लिए :
जब using directive को use किया जाता है और गार name already function मे declare है तब local variable इस global namespace के name को हाईड कर देता है |
इसके लिए using declartion को using directive ज्यादा use किया जाता है | और using declartion , using directive से safe होता है |
using directive से सभी name को इम्पोर्ट किया जाता है इसलिए इस method मे सभी name प्रोग्राम मे स्प्रेड हो जाता है और इसे handel करना थोडा complex हो जाता है |
इस article मे namespace के advance feature को discuss किया है अब आगे के article मे unnamed namespace और namespace के advance concept को 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 ,…