class vs namespace? [英] class vs namespace?
问题描述
大家好,
我们有一些现有的类要放入另一个
类或命名空间,这样我们就可以避免了命名冲突。至于
从使用角度来看,我可以看到语法相同。
有没有人对此有任何意见?
谢谢
Dean
Hi all,
We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.
Does anyone have an opinion on this either way?
Thanks
Dean
推荐答案
dean< de *********@yahoo.comwrote:
dean <de*********@yahoo.comwrote:
大家好,
我们现有几个我们想要放入另一个类b $ b类或命名空间的类,以便我们可以避免命名冲突。至于
从使用角度来看,我可以看到语法相同。
有没有人对此有任何意见?
Hi all,
We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.
Does anyone have an opinion on this either way?
为了您的目的,命名空间是可行的方法。您可以重新打开
命名空间并在翻译单元之间添加内容。你不能用课程来做这个
。此外,使用类意味着您可以创建该类的
实例,据我所知,情况并非如此。
hth
-
jb
(rot13中的回复地址,先解读)
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.
hth
--
jb
(reply address in rot13, unscramble first)
Jakob Bieling写道:
Jakob Bieling wrote:
dean< de ********* @ yahoo.comwrote:
dean <de*********@yahoo.comwrote:
>大家好,
我们有一些现有的类,我们想要放入另一个类或命名空间,这样我们就可以避免命名冲突。至于
从使用角度来看,我可以看到语法是相同的。
有没有人对此有任何意见?
>Hi all,
We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.
Does anyone have an opinion on this either way?
为了您的目的,命名空间是可行的方法。您可以重新打开
命名空间并在翻译单元之间添加内容。你不能用课程来做这个
。此外,使用类意味着您可以创建该类的
实例,据我所知,实例并非如此。
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.
此外,您可以使用带有名称空间的using声明,以及使用类可能不是
的AFAIK,至少不是你不是从他们那里得到的。
Also, you can use using-declarations with namespaces, and AFAIK that''s not
possible with classes, at least not if you don''t derive from them.
那么如果我们使用
$ b $那么该如何处理该类的成员变量b命名空间代替?我的意思是,如何隐藏私有变量并且只允许
允许访问器(获取和设置)功能?将成员变量放在命名空间的
之外但与命名空间位于同一单位?
Rolf Magnus写道:
So what to do about member variables of the class, if we use a
namespace instead? I mean, how can one hide a private variable and just
allow accessor (get and set) functions? Put the member variable outside
of the namespace but in the same unit as the namespace?
Rolf Magnus wrote:
Jakob Bieling写道:
Jakob Bieling wrote:
dean< de ********* @ yahoo.comwrote:
dean <de*********@yahoo.comwrote:
大家好,
我们有一些现有的类,我们想把它们放到另一个
类或命名空间中,所以我们可以避免命名冲突。至于
从使用角度来看,我可以看到语法相同。
有没有人对此有任何意见?
Hi all,
We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.
Does anyone have an opinion on this either way?
为了您的目的,命名空间是可行的方法。您可以重新打开
命名空间并在翻译单元之间添加内容。你不能用课程来做这个
。此外,使用类意味着您可以创建该类的
实例,据我所知,实例并非如此。
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.
另外,你可以使用带有命名空间的using声明,而AFAIK可以使用类,而不是
可以使用类,至少不是你不是从他们那里得到的。
Also, you can use using-declarations with namespaces, and AFAIK that''s not
possible with classes, at least not if you don''t derive from them.
这篇关于class vs namespace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!