虚函数 vs 动态函数

C++中有虚函数。而Delphi中既有虚函数还有动态函数。二者在语义上是等价的。

Virtual and dynamic methods are semantically equivalent. They differ only in the implementation of method-call dispatching at runtime.

区别在于虚函数优化了速度,而动态函数优化了代码大小

Virtual methods optimize for speed, while dynamic methods optimize for code size.

In general, virtual methods are the most efficient way to implement polymorphic behavior.

总体上来讲,虚函数是实现多态行为的最有效的方法

Dynamic methods are useful when a base class declares many overridable
methods which are inherited by many descendant classes in an application, but only
occasionally overridden.

当基类声明了很多可重写但是很少重写的方法时使用动态函数,
这样可一减小代码大小。在设计Framework时常使用这个技术

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top