Namespace
//Foo.h
#ifndef FOO_H
#define FOO_H
#include <iostream>

namespace Foo
{
	void display()
	{
		std::cout<<"display() in Foo ..."<<std::endl;
	}
}
#endif

//Util.h
#ifndef UTIL_H
#define UTIL_H
#include <iostream>

namespace Foo
{
	void info()
	{
		std::cout<<"info() in Foo ..."<<std::endl;
	}
}
#endif

//Goo.h
#ifndef GOO_H
#define GOO_H
#include <iostream>

namespace Goo
{
	void display()
	{
		std::cout<<"display() in Goo ..."<<std::endl;
	}
}
#endif

//main.cpp
#include <iostream>
#include "Foo.h"
#include "Goo.h"
#include "Util.h"

int main(int argc, char *argv[])
{
	Foo::display();
	Goo::display();

	Foo::info();

	return 0;
}
			
Nested Namespace
//Foo.h
#ifndef FOO_H
#define FOO_H
#include <iostream>

namespace Foo
{
	namespace Goo
	{
		void display()
		{
			std::cout<<"display() in Foo ..."<<std::endl;
		}
	}
}
#endif

//main.cpp
#include <iostream>
#include "Foo.h"

int main(int argc, char *argv[])
{
	Foo::Goo::display();

	return 0;
}
			
Search Path
//Foo.h
#ifndef FOO_H
#define FOO_H
#include <iostream>
#include "Goo.h"
#include "Util.h"

namespace Foo
{
	void display()
	{
		std::cout<<"display() in Foo ..."<<std::endl;
	}

	void callInfo()
	{
		info();
		Foo::info();
		Goo::info();
	}
}
#endif

//Util.h
#ifndef UTIL_H
#define UTIL_H
#include <iostream>

namespace Foo
{
	void info()
	{
		std::cout<<"info() in Foo ..."<<std::endl;
	}
}
#endif

//Goo.h
#ifndef GOO_H
#define GOO_H
#include <iostream>

namespace Goo
{
	void display()
	{
		std::cout<<"display() in Goo ..."<<std::endl;
	}

	void info()
	{
		std::cout<<"info() in Goo ..."<<std::endl;
	}
}
#endif

//main.cpp
#include <iostream>
#include "Foo.h"
#include "Goo.h"
#include "Util.h"

int main(int argc, char *argv[])
{
	Foo::callInfo();

	return 0;
}
			
Class in Namespace
//Vehicle.h
#ifndef VEHICLE_H
#define VEHICLE_H
#include <iostream>
#include <string>

namespace Foo
{
	class Vehicle
	{
		private:
			std::string producer;
		public:
			//constructor
			Vehicle(std::string s);

			std::string getProducer() const {return producer;}
			void setProducer(std::string producer);

			virtual std::string toString();

			virtual ~Vehicle();
	};
}
#endif

//Vehicle.cpp
#include <iostream>
#include <string>
#include "Vehicle.h"

//constructor
Foo::Vehicle::Vehicle(std::string s):producer(s)
{
	std::cout<<"Vehicle Constructor ..."<<std::endl;
}

void Foo::Vehicle::setProducer(std::string producer)
{
	this->producer = producer;
}

std::string Foo::Vehicle::toString()
{
	std::string temp;
	temp = "Vehicle Producer: "+producer;
	return temp;
}

Foo::Vehicle::~Vehicle()
{
	std::cout<<"Vehicle Destructor ..."<<std::endl;
}

//Car.h
#ifndef CAR_H
#define CAR_H
#include <iostream>
#include <string>
#include "Vehicle.h"

namespace Foo
{
	class Car : public Vehicle
	{
		private:
			std::string model;
		public:
			//constructor
			Car(std::string p, std::string m);

			std::string getModel() const {return model;}
			void setModel(std::string model);

			std::string toString();

			~Car();
	};
}
#endif

//Car.cpp
#include <iostream>
#include <string>
#include "Vehicle.h"
#include "Car.h"

namespace Foo
{
	//constructor
	Car::Car(std::string p, std::string m):Vehicle(p), model(m)
	{
		std::cout<<"Car Constructor ..."<<std::endl;
	}

	void Car::setModel(std::string model)
	{
		this->model = model;
	}

	std::string Car::toString()
	{
		std::string temp;
		temp = "Car Producer: "+getProducer()+" Model: "+model;
		return temp;
	}

	Car::~Car()
	{
		std::cout<<"Car Destructor ..."<<std::endl;
	}
}

//main.cpp
#include <iostream>
#include "Vehicle.h"
#include "Car.h"

int main(int argc, char *argv[])
{
	Foo::Vehicle v("Buick");
	std::cout<<v.toString()<<std::endl;

	Foo::Car c("Honda", "Accord");
	std::cout<<c.toString()<<std::endl;

	return 0;
}
			
Class in Namespace