------------------------------------------------------------------------------
MC logo
Using Namespaces
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Functional Average] [Functional Average II] [Functional Average III] [Default Parameters] [Function Overloading] [Reference Parameters] [Constant References] [Namespaces] [Namespaces I] [Using Namespaces]
nspace2.cpp
#include <iostream>
using namespace std;

namespace joe {
void alice();
int sally(int);
}

namespace fred {

void alice()
{
        cout << "Hi!  I'm alice in namespace fred." << endl;
        joe::alice();
}

int jane(int n)
{
        alice();
        cout << "Jane in namespace fred got " << n << endl;
        return n - 5;;
}

}

namespace joe {

using namespace fred;

void alice()
{
        cout << "Greetings from joe::alice." << endl;
}

int sally(int j)
{
        int ret = j + 7*jane(j);
        cout << "Well, joe::sally got " << j << " and is returning " << ret 
             << endl;
        return ret;
}

}

using joe::sally;

main()
{
        cout << "Go..." << endl;
        cout << "Sally gave us " << sally(8) << endl;
        cout << "...Stop" << endl;
}