+ 2

What is the main use of namespace? And what if we don't use it in our program?

2nd Feb 2017, 1:11 PM
Ashu Bagul
Ashu Bagul - avatar
2 Réponses
+ 3
Namespaces are used in C++ to organize code. You can easyle define your own namespace: namespace myNamespace{ // your normal C++ code } You get access to a function or member or class or whatever in a namespace by the :: syntax. So you would get access to the namespace defined above vy myNamespace::myFunction() If you dont want to write that much, use "using namespace myNamespace" and you can use myFunction directly. There are some very big namespaces in C++ and one of them contains the standard library. Its name ist std. thats why you have to use using namespace std or std::
2nd Feb 2017, 2:04 PM
~datell