Jump to content

C++ Programming/Scope/Examples/Program Namespaces

From Wikibooks, open books for an open world

This is the current revision of this page, as edited by DannyS712 (discuss | contribs) at 06:36, 16 April 2020 (Update syntaxhighlight tags - remove use of deprecated <source> tags). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
// Namespaces Program, an example to illustrate the use of namespaces #include <iostream> namespace first {  int first1;  int x; } namespace second {  int second1;  int x; } namespace first {  int first2; } int main(){  //first1 = 1;  first::first1 = 1;  using namespace first;  first1 = 1;  x = 1;  second::x = 1;  using namespace second;  //x = 1;  first::x = 1;  second::x = 1;  first2 = 1;  //cout << 'X';  std::cout << 'X';  using namespace std;  cout << 'X';  return 0; }