<<< Useful idea: Namespaces     Index     Namespace usage >>>

2. Namespace syntax


  • 
    // mylibrary.h
    namespace mylibrary {
    
        class IntStack {
        public:
            void push( int value );
            //...
        };
    
        class Rational {
        public:
            Rational& operator=( Rational const& other );
            //...
        };
    
    } // No closing namespace semicolon
    
    
  • Namespaces can be re-opened:

    
    // IntStack.cpp
    namespace mylibrary {
        void IntStack::push( int value )
        {
            // ...
        }
    }
    
    
    
    // Rational.cpp
    mylibrary::Rational rat;
    
    namespace mylibrary {
        Rational& Rational::operator=( Rational const& other )
        {
            //...
        }
    }
    
    

<<< Useful idea: Namespaces     Index     Namespace usage >>>