WhatsApp Group Join Now
Telegram Join Join Now

c++ : namespace , method to declare and directive in c++ language , program example source code in hindi

program example source code in hindi , c++ : namespace , method to declare and directive in c++ language :-
इससे पहले के article मे , namespace को discuss किया था अब इस article मे name को declare और directive करने के method को discuss करेगे | c++ language मे namespace को दो प्रकार से mechanism को बनाया गया है |
1.using declatarion
2.using Directive
दोनों method से namespace को use करने के method को सरल करता है | using declatarion method से namespace के element / name को use किया जा सकता है और using Directive से पुरे namespace को एक साथ use किया जासकता है | निन्म उदहारण मे
namespace pick{
double stick ; // variable declare
void acess(); // Funciotn declare
int b; // variable declare
struct pick_value{….}; // struture declare
}
namespace put {
double bucket (double n ){……..} // Funciotn declare
void acess(); // variable declare
int b; // variable declare
struct pick_value{….}; // struture declare
}इस उदाहरन मे दो namespace को declare किया गया है \
1.pick : इसमें 4 name है | पहला stick है जिसमे से वाले को pick करना है | दूसरा acess function का नाम है जिसका use वाले को access करने के लिए किया जाता हो | और pick_value struture का नाम है जिसमे pick की गयी value को hold किया जाता है |
1.put : इसमें 4 name है | पहला bucket है जिसमे pick की गयी values को put करना है | दूसरा acess function का नाम है जिसका use, access की गयी value को use करने के लिए किया जाता है | और pick_value struture का नाम है जिसमे pick की गयी value को hold किया जाता है |

1.using declatarion
इन namespace को acess करने के लिए using declatarion method को निन्म तरह से use करते है :-
using pick : : acess ; // using declatarion

using declatarion method मे namespace मे से name को किसी declartion region के फिक्स किया जा सकता है | उपर वाले उदहारण मे , name space pick के function access () के लिए declatarion region main() होता है | इस declartion के बाद access () function को main() function मे कभी भी use किया जा सकता है |
अतः code इस तरह होगा |
namespace pick{
double stick ; // variable declare
void acess(); // Funciotn declare
int b; // variable declare
struct pick_value{….}; // struture declare
}
char access ;
int main()
{
using pick :: access ;
int acess ;
cin>>acess ;
cin>>::acess ;
}

using declartion region से name का scope local होता है | और जब किसी दुसरे name access को declare किया जाता है | तब इस statement से global name को local name से ओवरराइड हो जाता है |

using declartion region से name space मे नए name को add किया जाता है इसके लिए निन्म उदाहरन को consider करेगे |
void other ()
{
namespace pick{
double stick ; // variable declare
void acess(); // Funciotn declare
int b; // variable declare
struct pick_value{….}; // struture declare
}
using pick :: acess ()
int main()
{
cin>>access;
other ;
……;
}
void other ()
{
cout<<acess ;
……
}

namespace pick{
double stick ; // variable declare
void acess(); // Funciotn declare
int b; // variable declare
struct pick_value{….}; // struture declare
}

2.using Directive
using Directive method से namespace के सभी names को use किया जा सकता है | using Directive से किसी namespace के names को add किया जाता है | ये namespace के सभी names को include किया जाता है इसका syntax निन्म होता है :
using namespace pick;

जब किसी namespace को global declare किया जाता है | इस namespace के सभी name को प्रोगार्म के किसी भाग मे use किया जा सकता है | इससे पहले कई उदाहरनो मे हमने देखा है की
#include<iostream>
using namespace std;
जब किसी namespace को using Directive से किसी function मे add किया जाता है तब इस namespace को केवल इस function मे use किया जासकता है | इसका उदहारण निन्म है :
int main()
{
using namespace pick ;
}

जब किसी using Directive या using declatarion को use किया जाता है तब इससे name मे confusion होता है | जब दोनों pick और put namespace को उज्से किया जासकता है तब in namespace से variable a को use किया जाता है तब name मे confusion हो सकता है |

using Directive method मे namespace मे से name को किसी region मे use किया जा सकता है | उपर वाले उदहारण मे , name space pick के function access () के लिए declatarion region main() के अलावा function add() मे भी use किया जा सकता है | इस declartion के बाद access () function को main() function और add() मे कभी भी use किया जा सकता है |
अतः code इस तरह होगा |
namespace pick{
double stick ; // variable declare
void acess(); // Funciotn declare
int b; // variable declare
struct pick_value{….}; // struture declare
}
char access ;
using namespace pick;
int main()
{
int acess ;
cin>>acess ;
cin>>::acess ;
}
void add()
{
pick ::a;
::a=10 ;
cout<<“value :”<<a;
}

using Directive region से name का scope global होता है | और जब किसी दुसरे name access को declare किया जाता है जिसका variable local scope होता है तब इस statement से global name को local name से ओवरराइड हो जाता है |

इस article मे namespace को access करने के लिए method को discuss किया है आगे के article मे using Directive और using declaration के बारे मे advance topic को discuss करेगे |