Use namespaces to wrap variables : NameSpace « Language « C++






Use namespaces to wrap variables

  
#include <iostream>
using namespace std;

namespace first
{
  int var = 5;
}

namespace second
{
  double var = 3.1416;
}

int main () {
  cout << first::var << endl;
  cout << second::var << 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.Enclosure variables with namespace
10.Defines and tests namespaces.Defines and tests namespaces.