Namespace and Separate Compilation

Namespace and Separate Compilation - Lecture 5b: Namespaces...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 5b: Namespaces and Separate Compilation • A namespace is a collection of name definitions – Class names, variable names, … • When a program uses different classes and functions written by different programmers – Possible that the same name was referred to two different things • Need to specify the namespaces with the using directive Ex: using namespace std; std Namespace • The std namespace contains all the names defined in the standard library files – Ex: #include <iostream> places all name definitions in the iostream library such as cin and cout into the std namespace – Your program doesn’t know about names in the std namespace unless you specify that it is using the std namespace as follows using namespace std; Creating a Namespace • Format Namespace Namespace_Name { some_code } • Example namespace ns1 { //declaration namespace ns2 { void greeting(); void greeting(); void print(); void display(); } } namespace ns1 { //definition or implementation void greeting () {cout << “greeting from namespace #1\n”; return;} …} Using Multiple Namespaces...
View Full Document

This note was uploaded on 12/18/2008 for the course CS 256 taught by Professor Dr. yang during the Fall '08 term at Cal Poly Pomona.

Page1 / 7

Namespace and Separate Compilation - Lecture 5b: Namespaces...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online