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

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.
我们将更为详细的讨论。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值