命名空间中是否存在“私有”? [英] Is there 'private' in namespace?

查看:105
本文介绍了命名空间中是否存在“私有”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道命名空间中是否有某些内容,例如类中的''private''

关键字?


我想定义一些只能在

命名空间内使用的类或函数。


谢谢,


Hi,

I''m wondering if there is something in namespace like the ''private''
keyword in class?

I want to define some class or function that can only be used within
that namespace.

Thanks,
Peng

推荐答案

2008年7月23日星期三,彭宇写道:
On Wed, 23 Jul 2008, Peng Yu wrote:

我想定义一些只能在

命名空间内使用的类或函数。
I want to define some class or function that can only be used within
that namespace.



我认为不可能限制访问全球可用的

级别。如果您正在寻找只能在

名称空间中使用的函数,那么请使用类和静态方法。

I don''t think it''s possible to restrict access to a globally available
class. If you are looking for functions that can only be used within
namespaces, then use a class and static methods.


7月24日,2 :58:00,Peng Yu< PengYu ... @ gmail.comwrote:
On Jul 24, 2:58 am, Peng Yu <PengYu...@gmail.comwrote:

我想知道名字空间中是否有像
这样的东西
''private''关键字在课堂上?
I''m wondering if there is something in namespace like the
''private'' keyword in class?


我想定义一些只能在该命名空间中使用的类或函数


I want to define some class or function that can only be used
within that namespace.



命名空间是开放的(任何人都可以在命名空间中添加成员,

),所以没有任何意义。


-

James Kanze(GABI软件)电子邮件:ja ********* @ gmail.com

conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.-Cyr-l''coco,France,+ 33(0) 1 30 23 00 34

Namespaces are open (anyone can add a member to a namespace,
anywhere), so there''s no point in private.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


7月24日凌晨2:48,James Kanze< james.ka ... @ gmail.comwrote:
On Jul 24, 2:48 am, James Kanze <james.ka...@gmail.comwrote:

7月24日凌晨2:58,彭宇< PengYu ... @ gmail.com写道:
On Jul 24, 2:58 am, Peng Yu <PengYu...@gmail.comwrote:

我'我想知道命名空间中是否有类似

''private''关键字的东西?

我想定义一些只能使用的类或函数

在该命名空间内。
I''m wondering if there is something in namespace like the
''private'' keyword in class?
I want to define some class or function that can only be used
within that namespace.



命名空间是开放的(任何人都可以在命名空间中添加成员,

),所以没有任何意义。


Namespaces are open (anyone can add a member to a namespace,
anywhere), so there''s no point in private.



我认为命名空间中的私有可能有用。


例如,我是代码a命名空间N中的C类。为了编码C,我可能需要定义一些类或函数,除了C之外的其他类别的b $ b类不使用它。我不想要在C方面定义这些类或

函数,因为如果我这样做,我就无法将b / b
分成两个不同的文件,会让它变得难以测试和理解代码。


因为这些类或函数是针对C的,所以我想将它们保存在

与C相同的命名空间。


由于这些类或函数不适用于除

C以外的其他类,理想情况下,我想在C ++中以某种方式指定它们仅用于C

。现在,我可能想到的是在

''命名空间''中添加''private'',这样至少N以外的课程将无法支付
称这些功能或类别。


谢谢,


I''d think a private in namespace might be useful.

For example, I''m code a class C in namespace N. To code C, I might
need define some classes or functions, which are not used by other
classes other than C. I would not want to defines these classes or
functions in side C, because if I do it this way, I would not be able
to separate them from C into two different files, which would make it
harder to test and understand the code.

Since these classes or functions are for C, I''d like to keep them in
the same namespace as C.

Since these classes or functions are not for other classes other than
C, ideally, I would like to specify somehow in C++ that they are for C
only. For now, what I can possibly think of is to add ''private'' in
''namespace'' such that at least classes outside N would not be able to
call these functions or classes.

Thanks,
Peng


这篇关于命名空间中是否存在“私有”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆