google.com, pub-7659628848972808, DIRECT, f08c47fec0942fa0 Pro Learner: namespace in cpp

Please click on ads

Please click on ads

Monday 4 January 2021

namespace in cpp

 Namespace is used  as additional information  to differentiate between function.

Defines the context in which names are defined.

Syntax:

namespace namespace_name{

//codding

}

Access a namespace 

access a namespace -enable entity 

name::code;//code will be variable or function

The  using directive

It tells the compiler that subsequent code is making use of names in specified name space.

Example--

// Creating namespaces

#include <iostream>

using namespace std;

namespace ns1

{

int value() { return 10; }

}

namespace ns2

{

double value() { return 0.5; }

}

using namespace ns1;

int main()

{

cout <<value() << '\n';


return 0;

}


No comments:

Post a Comment