A namespace can be nested within another : NameSpace « Language « C++






A namespace can be nested within another

A namespace can be nested within another
 
#include <iostream>
using namespace std;
namespace MyNameSpace1 {
  int i;
  namespace MyNameSpace2 { // a nested namespace
    int j;
  }
}
int main()
{
  MyNameSpace1::i = 19;

  MyNameSpace1::MyNameSpace2::j = 10;
  cout << MyNameSpace1::i << " "<<  MyNameSpace1::MyNameSpace2::j << "\n";

  using namespace MyNameSpace1;
  cout << i * MyNameSpace2::j;
  return 0;
}

           
         
  








Related examples in the same category

1.Namespace Demo: define a namespaceNamespace Demo: define a namespace
2.Namespaces are additiveNamespaces are additive
3.Demonstrate a namespaceDemonstrate a namespace
4.Some Namespace OptionsSome Namespace Options
5.use explicit std:: qualification.use explicit std:: qualification.
6.Using namespace to reference variables
7.Namespace code section
8.Use namespaces to wrap variables
9.Enclosure variables with namespace
10.Defines and tests namespaces.Defines and tests namespaces.