Short Note On Namespace in C++

No comments



Namespace :-   Suppose we want to develop an interactive math program, For this program function like cos( ), sin( ), tan( ), etc are to be used accepting arguments in radiant. Unfortunately  , the function name cos( ) is already in use and that function accepts radiant as its arguments, rather than degrees. Problems like these are normally solved by looking for another name.
C++ offers an alternative solution by allowing namespace to be defined : areas or regions in the code in which identifiers are defined which cannot conflict with existing names defined else where.

Syntax –
namespace identifier
{
     //declared or defined entities
   //(declarative region)
}
Within the declarative region, introduced in the above code example , function, variables, structs, classes and even (nested) namespaces can be defined and declared namespace can not be define within a block. This means that namespace ABCD could be define in a file file1.CPP and also in the file file2.CPP. The entity defined in namespace ABCD of file1 and file2 are united in one ABCD namespace region.

Example :-

// in file.CPP
namespace ABCD
{
     double cos(double arg_in_degree)
       {
            ---------------------------
        }
 }
//in file2.CPP
namespace ABCD
{
     Double sin(double arg_in_degree)
       {
            ---------------------------
        }
 }

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀