|
From: Ioannis V. <no...@ho...> - 2002-06-18 11:10:12
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Daniel Glenfield
> Sent: Tuesday, June 18, 2002 1:36 PM
> To: dev...@li...
> Subject: [Dev-C++] ioannis - namespaces
>
>
> Ioannis, you've mentioned several times to always use
> namespaces as locally
> as possible. I was wondering why this is? What is the benefit
> of using them
> locally?
>
> Daniel
The namespace system was made to provide a system that enables combining
various libraries while protecting from name clashes.
So you can for example do:
#include <iostream>
// Daniel's version of vector
#include <daniel.h>
int main()
{
using std::cout;
using daniel::vector;
vector<int>array(50, 1);
cout<<array[i]<<endl;
}
As god says in TC++PL, using global using directives is an efffort to
defeat the namespace system, which has bad consequences in large
projects. We must try to use more using std::something; than using
namespace std; and as in small scope as possible.
In general myself, i use using std::something; for 2-3 facilities in a
given function, and if there are more i place a using namespace std; in
that function scope.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|