While writing big programs involving several programmers, things are likely to go out of hand if proper control is not exercised over visibility of these names.
//mylib.h char fun() void display(); class CMath{...}; //somelib.h class CMath{...}; void display();If both these header files are included in a program, there would be a clash between the two CMath classes. A solution would be to create long names which have lesser chances of clashing but the programmers are required to type these long names. But C++ provides a better solution through a keyword named namespace. C++ provides a single global name spaces. The global name space can be sub-divided into more manageable pieces using name space feature in C++.
//mylib.h namespace myheader { char fun() void display(); class CMath{...}; } //somelib.h namespace somelib { class CMath{...}; void display(); }The class names will not clash as they become mylib::CMath and somelib::CMath respectively. Same thing would happen to the function names.
About our authors: Team EQA
You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.