namespace(C++名字空间)(2)

来源:互联网 发布:icsd数据库 编辑:程序博客网 时间:2024/05/19 18:48

Exposing all the elements from a namespace after someone has
在库函数作者已经把所有元素隐藏之后,再从名字空间引用看起来是
gone to the trouble to hide them may seem a bit counterproductive,
有些费事不讨好,
and in fact you should be careful about thoughtlessly doing this (as
 事实上,也是这样你得很认真的考虑这样的应用(后面我们将就此展开讨论)
you'll learn later in the book). However, the  directive using
不过,能过using关键字,你只能在当前文件中引用那些名字,
exposes only those names for the current file, so it is not quite as
这样一来,关于using的使用就不像起初听起来那么生硬了。
drastic as it first sounds. (But think twice about doing it in a header
(但是,在一个头文件中这样做时一定要多考虑,因为这样做可能有不少麻烦。)
file--that is reckless.)

There's a relationship between namespaces and the way header
在名字空间与头文件的引用方式间有一种联系。
files are included. Before the modern header file inclusion was
在头文件引用机制标准化以前,通常是加'.h'后辍。那时,名字空间的概念还
standardized (without the trailing '.h', as in <iostream>), the
typical way to include a header file was with the '.h', such as
<iostream.h>. At that time, namespaces were not part of the
language either. So to provide backward compatibility with 
正式成为此语言的一部分。所以,为了与现有的代码保持兼容,
existing code, if you say
用“#include <iostream.h> ”也就等同于
“#include <iostream>
using namespace std;”了。
 
#include <iostream.h>
 
it means

#include <iostream>
using namespace std;
 
However, in this book the standard include format will be used
不过,本书中,还是标准的引入格式,即没有“.h”后辍
(without the '.h') and so the  directive using must be explicit.
,using关键字也得必须使用。
For now, that's all you need to know about namespaces, but in
到现在为止,对名字空间的讨论也是你现在应该了解的,随后在第10章,
Chapter 10 the subject is covered much more thoroughly.
我们将更为详细的讨论。