最终和Cieled并没有在C ++中 [英] Final and Cieled and nothing in C++

查看:80
本文介绍了最终和Cieled并没有在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实上Java和C#都是垃圾收集,C ++没有收集,

与事实上没有任何语言项来阻止

类从继承?我曾经读过Java和C#实现这个

功能的性能,但是C ++的创建者说它并没有更糟糕的

努力。所以因为Java和C#是垃圾收集的,在他们的情况下是不是更糟糕的努力?连接是什么?

Has the fact that both Java and C# are garbage collected, and C++ in not,
anything to do with the fact that there is no language item to prevent a
class from being inherired from? I once read that Java and C# implement this
feature for preformance, but the C++ creators said it was not worse the
effort. So because Java and C# are garbage collected, in their case is it
worse the effort? What is the connection?

推荐答案

My4thPersonality写道:
My4thPersonality wrote:
事实上Java和C#都是垃圾收集的,
和C ++没有,有什么事实与
没有语言项来阻止一个类被继承?我曾经读过Java和C#实现此功能的性能,但是C ++的创建者说,这并不是更糟糕的努力。那么因为Java和C#被垃圾收集,在他们的情况下是不是更努力?
什么是连接?
Has the fact that both Java and C# are garbage collected,
and C++ in not, anything to do with the fact that there
is no language item to prevent a class from being
inherired from? I once read that Java and C# implement
this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are
garbage collected, in their case is it worse the effort?
What is the connection?




"为什么难道C ++没有垃圾收集吗?
http://www.research.att.com/~bs/bs_f...age-collection




My4thPersonality <所以******* @ out.there> skrev i meddelandet

新闻:u2 ************* @ TK2MSFTNGP10.phx.gbl ...

"My4thPersonality" <so*******@out.there> skrev i meddelandet
news:u2*************@TK2MSFTNGP10.phx.gbl...
这两个事实都是Java和C#是垃圾收集,而C ++中没有,与没有语言项的事实有什么关系来阻止一个类被继承?我曾经读过Java和C#实现此功能的性能,但是C ++的创建者说,这并不是更糟糕的努力。那么因为Java和C#都是垃圾收集,在他们的情况下是不是努力了?什么是
连接?
Has the fact that both Java and C# are garbage collected, and C++ in
not, anything to do with the fact that there is no language item to
prevent a class from being inherired from? I once read that Java and
C# implement this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are garbage
collected, in their case is it worse the effort? What is the
connection?




这不是关于垃圾收集,而是关于虚拟功能。在

C ++中,一个函数不是虚拟的,除非你特意这样做。

几乎不需要指定''final'来制作

再次运行非虚拟 - 只是不要在第一个

的地方虚拟!


另外,你可以防止继承C ++类,但是使用它来构造私有的
。虽然这并没有用得多。通常的方法是在文档中添加一个注释,这个类不是为了继承而设计的b $ b。

Bo Persson



It is not about garbage collection, it is about vitual functions. In
C++, a function isn''t virtual, unless you specifically make it so.
That pretty much removes the need to specify ''final'' to make the
functions non-virtual again - just don''t make it virtual in the first
place!

Also, you can prevent a C++ class from being inherited from, but
making its constructor private. This isn''t used very much though. The
usual way is to add a note in the documentation, "This class isn''t
designed for inheritance".
Bo Persson


Bo Persson写道:
Bo Persson wrote:
" My4thPersonality" <所以******* @ out.there> skrev i meddelandet
新闻:u2 ************* @ TK2MSFTNGP10.phx.gbl ...
"My4thPersonality" <so*******@out.there> skrev i meddelandet
news:u2*************@TK2MSFTNGP10.phx.gbl...
事实上Java和C#都是垃圾收集,和C ++在
中没有任何关系,因为没有语言项来阻止一个类被继承?我曾经读过Java和C#实现此功能的性能,但是C ++的创建者说,这并不是更糟糕的努力。那么因为Java和C#都是垃圾收集,在他们的情况下是不是努力了?什么是
连接?
Has the fact that both Java and C# are garbage collected, and C++ in
not, anything to do with the fact that there is no language item to
prevent a class from being inherired from? I once read that Java and
C# implement this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are garbage
collected, in their case is it worse the effort? What is the
connection?



它不是关于垃圾收集,而是关于虚拟功能。在C ++中,一个函数不是虚拟的,除非你特意这样做。
这几乎不需要指定''final''来使
函数非虚拟化再次 - 只是不要在第一个地方虚拟它!

此外,你可以阻止C ++类继承,但是使其构造函数变为私有。虽然这并没有用得多。通常的方法是在文档中添加一个注释,此类不是为继承而设计的。



It is not about garbage collection, it is about vitual functions. In
C++, a function isn''t virtual, unless you specifically make it so.
That pretty much removes the need to specify ''final'' to make the
functions non-virtual again - just don''t make it virtual in the first
place!

Also, you can prevent a C++ class from being inherited from, but
making its constructor private. This isn''t used very much though. The
usual way is to add a note in the documentation, "This class isn''t
designed for inheritance".




那个说,final / sealed在C ++中作为优化是有用的,因为它们允许编译器在一些有用的情况下轻松确定虚拟

函数的最终覆盖。做整个程序分析。我认为许多C ++程序员都欢迎能够将类标记为不是

可继承的能力。

。这是一个很常见的情况,习惯于用b ++来阻止它的习惯用法是最好的,而不是正确的语言功能。很容易

相处没有,是的,但仍然很高兴。


-cd



That said, final/sealed would be useful in C++ as an optimization, since
they allow the compiler to easily determine the final overrider of a virtual
function in some useful cases without doing whole program analysis. I think
that many C++ programmers would welcome the ability to mark a class as "not
inheritable". It''s a common enough situation, and the idioms used to
prevent it in C++ are hacks at best, not proper language features. Easy to
get along without, yes, but still nice to have.

-cd


这篇关于最终和Cieled并没有在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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