本文介绍了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

推荐答案



为了您的目的,命名空间是可行的方法。您可以重新打开

命名空间并在翻译单元之间添加内容。你不能用课程来做这个

。此外,使用类意味着您可以创建该类的

实例,据我所知,情况并非如此。


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)




为了您的目的,命名空间是可行的方法。您可以重新打开

命名空间并在翻译单元之间添加内容。你不能用课程来做这个

。此外,使用类意味着您可以创建该类的

实例,据我所知,实例并非如此。


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.




为了您的目的,命名空间是可行的方法。您可以重新打开

命名空间并在翻译单元之间添加内容。你不能用课程来做这个

。此外,使用类意味着您可以创建该类的

实例,据我所知,实例并非如此。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:48
查看更多