Namespaces in C++ All about namespaces Learn faster and better than others here.


NAMESPACES ARE USED TO :
⦁    Name a block of code for future reference .
⦁    Give scope to variables.
NAMESPACES HAVE ADVANTAGES:
⦁    Resolve naming issues like boost::regex and std::regex .
FEATURES:
⦁    Until specified the statements of the namespace would not be executed.
⦁    Namespaces named the same in the source code are treated as a merged namespace.This implies that there can be only one namespace with a single name and if you try to redefine it,you are actually concatenating it.
⦁    The using keyword lets you make the mentioned class or function etc in scope of the function typed in like :
..      
..
   using namespace_name identifier; //common mistake is to use funct_name() instead of funct_name
..
⦁   One time use of a function/class(after that that function/class becomes out of scope.) can be done by using the scope resolution operator as namespace_name::function_or_class_name; Ex : std::cout<<"Hello";
⦁ In case of nested namespaces of form:
namespace external
{
 namespace internal
{

}
}
using namespace external ; will not make contents of internal available.
It must be used as
external::internal::identifier;
or simply
internal::identifier; when contents of external have already been made available.
⦁    using namespace namespace_name ; will make all contends of namespace namespace_name available to the functions only below it !. It can be used above all functions to make contents of it available to all functions or above selected functions.Also don't think that writing using namespace namespace_name once in a function will make it available for all functions.We can say that using namespace namespace_name is very position dependent.

⦁    COOL PHENOMENON:
When a namespace is defined,it includes the content of namespace with the same name.
like  namespace std {namespace std{}}









-> When a namespace is being defined,the content of namespace with the same name is already available. 




 RULES
⦁    Cannot  define namespaces inside functions.

[ NOTE: This site is optimized for fast learning with 100% completion and grasp of the topic discussed in an interesting way and respecting "Learning by examples". This site is written in a fashion that reduce any chances of development of a misconception.Predicted approach of presenting the view of the topic that you will ultimately develop after knowing the topic to use it absolutely is used.]

Appreciate my effort:

Appreciate my hardwork :

  Donate is totally optional.



Comments