namespace(C++名字空间)(2)
2007-06-12 10:11
302 查看
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.
我们将更为详细的讨论。
在库函数作者已经把所有元素隐藏之后,再从名字空间引用看起来是
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.
我们将更为详细的讨论。
相关文章推荐
- [C++基础]002_名字空间(namespace)
- C++技巧之名字空间namespace
- C++技巧之名字空间namespace
- C++引入名字空间(namespace)意义何在?为什么using namespace std会成为常用语句?
- [C++ rudiment]名字空间 namespace
- C++技巧之名字空间namespace
- c++ 静态类成员函数(static member function) vs 名字空间 (namespace)
- C++中的名字空间namespace
- C++_命名空间namespace 与 using编译指令 与 using声明使用。
- 关于c++名字解析的一个问题:名字空间污染
- C++学习笔记---内部类与名字空间
- 名字空间(namespace)
- C++ 命名空间namespace
- C++ 命名空间namespace .
- 杂货边角(22):名字空间namespace的一二事
- C++名字空间详解
- C++ using namespace std 详解 与 命名空间的使用
- C++ namespace 命名空间详解
- 名字空间(namespace)和包(package)(TCL) 原则1和2
- C++ 命名空间namespace .