std析构函数 [英] std destructors

查看:122
本文介绍了std析构函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么std课程没有虚拟析构函数?


想继承这些课程并不是很有意义

添加/更改功能?

why don''t the std classes have virtual destructors?

doesn''t it make sense to want to inherit from these classes and
add/change functionality?

推荐答案


jq ******** @ gmail.com 写道:
为什么std类没有虚拟析构函数?
<想要继承这些类并添加/更改功能是不是有意义?
why don''t the std classes have virtual destructors?

doesn''t it make sense to want to inherit from these classes and
add/change functionality?




这通常不是一个好主意从具体类派生,因为

的部分赋值问题和混合类型赋值问题。它b / b
还表明你的设计需要新的潜在抽象。


查看Scott Meyers的更有效的C ++第33项。他清楚地解释了它。

。 (这是一本我们都应该保持方便的书。)


面向对象的设计启发式还提到了这个问题及其对b
的影响。


Belebele



It is usually not a good idea to derive from concrete classes because
of the partial assignment problem and mixed-type assignment problem. It
also shows the need for new potential abstractions in your design.

Check out item 33 on Scott Meyers'' More Effective C++. He explains it
all clearly. (That''s a book that we should all keep handy).

"Object Oriented Design Heuristics" also mentions the problem and its
implications.

Belebele


我猜我的问题是......为什么std类具体类?

Belebele写道:
I guess my question is... why are the std classes concrete classes?
Belebele wrote:
jq ******** @ gmail.com 写道:
为什么std类没有虚拟析构函数?
why don''t the std classes have virtual destructors?

doesn''t it make sense to want to inherit from these classes and
add/change functionality?



从具体类派生出来通常不是一个好主意因为部分分配问题和混合型分配问题。它还表明了对你的设计中新的潜在抽象的需求。

查看Scott Meyers的更有效的C ++第33项。他清楚地解释了这一切。 (这是一本我们都应该保持方便的书。)

面向对象的设计启发式还提到了这个问题及其影响。

Belebele



It is usually not a good idea to derive from concrete classes because
of the partial assignment problem and mixed-type assignment problem. It
also shows the need for new potential abstractions in your design.

Check out item 33 on Scott Meyers'' More Effective C++. He explains it
all clearly. (That''s a book that we should all keep handy).

"Object Oriented Design Heuristics" also mentions the problem and its
implications.

Belebele






jq ******** @ gmail.com 写道:
为什么不是std类有虚拟析构函数吗?

想继承这些类并添加/更改功能是不是有意义?
why don''t the std classes have virtual destructors?

doesn''t it make sense to want to inherit from these classes and
add/change functionality?




std :: exception有一个虚拟析构函数,仅举几例。如果

你关注的是编码风格指南,基类应该有b
虚拟析构函数,那么这个指南就太简单了。只有当类的设计通过指向基类型的指针要求删除

派生类型的对象时,才需要虚拟析构函数
。对于初学者来说可能太过复杂,因此需要更广泛的指导。


-


Pete Becker

Roundhouse Consulting,Ltd。



std::exception has a virtual destructor, to name just one of many. If
your concern is the coding style guideline that base classes should have
virtual destructors, that guideline is simplistic. A virtual destructor
is needed only if the design of the class calls for deleting objects of
derived types through pointers to the base type. For beginners that may
be too complicated, hence the broader guideline.

--

Pete Becker
Roundhouse Consulting, Ltd.


这篇关于std析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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