Defines and tests namespaces. : NameSpace « Language « C++






Defines and tests namespaces.

Defines and tests namespaces.
 

#include <string>       
                        
namespace MySpace
{
   std::string mess = "Within MySpace";
   int count = 0;       
   double f( double);   
}
namespace YourSpace
{
   std::string mess = "Within YourSpace";
   void f( ) {                    
      mess += '!';
   }
}
namespace MySpace               
{
   int g(void);            
   double f( double y)     
   {                       
     return y / 10.0;
   }
}
int MySpace::g( )             
{                             
   return ++count;
}
#include <iostream>   
int main()
{
  std::cout<< MySpace::mess << std::endl;
  MySpace::g();
  std::cout << "\nReturn value g(): " << MySpace::g()
            << "\nReturn value f(): " << MySpace::f(1.2)
            << std::endl;
  YourSpace::f();
  std::cout << YourSpace::mess << std::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.Enclosure variables with namespace