为什么RTTI需要? [英] Why is RTTI necessary?

查看:107
本文介绍了为什么RTTI需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么需要RTTI(运行时类型信息)?

Why is RTTI (Runtime Type Information) necessary?

推荐答案

RTTI,信息 为C ++引入了一种[温和]反射形式。

RTTI, Run-Time Type Information, introduces a [mild] form of reflection for C++.

它允许知道例如超类的类型,因此允许处理所有派生自相同基本类型的对象的异构集合。以特定于个别超类的方式。 (假设你有一个Vehicle对象数组,并且需要处理不同的数组中找到的Truck对象)。

It allows to know for example the type of a super class, hence allowing to handle an heterogeneous collection of objects which are all derived from the same base type. in ways that are specific to the individual super-classes. (Say you have an array of "Vehicle" objects and need to deal differently with the "Truck" objects found amid the array).

RTTI是否 必要 是一个开放的。故事使Bjarne Stroustrup有意将这个功能从原来的C ++规范中排除,因为它担心会被滥用。

确实有过度使用/滥用反射功能的机会,这可能是更多的这是C ++最初引入的一个因素,因为在主流程序员社区中没有这样的OOP文化。

这说明,有了更多的OOP精明的社区,有效地演示所有的好东西反射do(例如,使用Java或C#等语言),并且现在使用的花哨设计模式,我坚信RTTI和反射功能在很大程度上是非常重要的,即使有时被滥用。

The question whether RTTI is necessary is however an open one. Story has it that Bjarne Stroustrup purposefully excluded this feature from the original C++ specification, by fear that it would be misused.
There are indeed opportunities to overuse/misuse reflection features, and this may have been even more of a factor when C++ was initially introduced because there wasn't such a OOP culture in the mainstream programmer community.
This said, with a more OOP savvy community, with the effective demonstration of all the good things reflection can do (eg. with languages such as Java or C#) and with the fancy design patterns in use nowadays, I strongly believe that RTTI and reflection features at large are very important even if sometimes misused.

这篇关于为什么RTTI需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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