Enclosure variables with namespace : NameSpace « Language « C++

Enclosure variables with namespace

#include <iostream>
using namespace std;

namespace first
  int x = 5;
  int y = 10;

namespace second
  double x = 3.1416;
  double y = 2.7183;

int main () {
  using first::x;
  using second::y;
  cout << x << endl;
  cout << y << endl;
  cout << first::y << endl;
  cout << second::x << endl;
  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.A namespace can be nested within anotherA namespace can be nested within another
6.use explicit std:: qualification.use explicit std:: qualification.
7.Using namespace to reference variables
8.Namespace code section
9.Use namespaces to wrap variables
10.Defines and tests namespaces.Defines and tests namespaces.