CSC/ECE 517 Fall 2010/ch2 4d RB: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 3: Line 3:


=Why namespaces=
=Why namespaces=
In general programming languages like C++, variable names, function  names, structure names, class names, union names and enumerations fall under one general category called names. While writing big programs involving several programmers, the situation is likely to go out of hand if proper control is not exercised on the visibility of these names. For example, lets consider the following
In general programming languages like C++, variable names, function  names, structure names, class names, union names and enumerations fall under one general category called names. While writing big programs involving several programmers, the situation is likely to go out of hand if proper control is not exercised on the visibility of these names. For example, lets consider the following:
 
 
//library1.h
char hello();
void print();
class EmpSal
{
  char* ename;
  int esal;
}
 
// library2.h
char hi();
void print();
class EmpSal
{
  char* nm;
  float tax;
}

Revision as of 01:02, 21 November 2010

Introduction

Namespaces are used in Computer Science to group similar items into different logical units, so that one item can be un-ambigously differentiated from another item. Trivial it may seem, but creating namespaces is one of the most basic activities of modern day programming. It makes a program more organized and less prone to errors.

Why namespaces

In general programming languages like C++, variable names, function names, structure names, class names, union names and enumerations fall under one general category called names. While writing big programs involving several programmers, the situation is likely to go out of hand if proper control is not exercised on the visibility of these names. For example, lets consider the following:


//library1.h
char hello();
void print();
class EmpSal
{
  char* ename;
  int esal;
}
// library2.h
char hi();
void print();
class EmpSal
{
  char* nm;
  float tax;
}