zoukankan      html  css  js  c++  java
  • 动态绑定与动态分发-动态绑定暗含动态分发

    绑定:建立联系;

    分发:作出选择。

    https://en.wikipedia.org/wiki/Dynamic_dispatch

    https://en.wikipedia.org/wiki/Late_binding

    Dynamic dispatch is different from late binding (also known as dynamic binding). In the context of selecting an operation, binding refers to the process of associating a name with an operation. Dispatching refers to choosing an implementation for the operation after you have decided which operation a name refers to. With dynamic dispatch, the name may be bound to a polymorphic operation at compile time, but the implementation not be chosen until runtime (this is how dynamic dispatch works in C++). However, late binding does imply dynamic dispatching since you cannot choose which implementation of a polymorphic operation to select until you have selected the operation that the name refers to.

    Binding refers to the process of associating a name with an operation.

    the main thing here is function parameters these decides which function to call at runtime 

    Dispatching refers to choosing an implementation for the operation after you have decided which operation a name refers to.

    dispatch control to that according to parameter match

    http://en.wikipedia.org/wiki/Dynamic_dispatch

    hope this help you

    In C++, both are same.

    In C++, there are two kinds of binding:

    • static binding — which is done at compile-time.
    • dynamic binding — which is done at runtime.

    Dynamic binding, since it is done at runtime, is also referred to as late binding and static binding is sometime referred to as early binding.

    Using dynamic-binding, C++ supports runtime-polymorphism through virtual functions (or function pointers), and using static-binding, all other functions calls are resolved.

    The link itself explained the difference:

    Dynamic dispatch is different from late binding (also known as dynamic binding). In the context of selecting an operation, binding refers to the process of associating a name with an operation. Dispatching refers to choosing an implementation for the operation after you have decided which operation a name refers to. 

    and

    With dynamic dispatch, the name may be bound to a polymorphic operation at compile time, but the implementation not be chosen until runtime (this is how dynamic dispatch works in C++). However, late binding does imply dynamic dispatching since you cannot choose which implementation of a polymorphic operation to select until you have selected the operation that the name refers to.

    But they're mostly equal in C++ you can do a dynamic dispatch by virtual functions and vtables.

    C++ uses early binding and offers both dynamic and static dispatch. The default form of dispatch is static. To get dynamic dispatch you must declare a method as virtual.

  • 相关阅读:
    jQuery之第4章 jQuery中的事件和动画
    jQuery之第3章 jQuery中的DOM操作
    jQuery之第2章 jQuery选择器
    输入一组学生的姓名和成绩,根据成绩降序排名。
    抽象类和接口
    pingpong线程输出问题
    sql优化
    [leedcode 242] Valid Anagram
    [leedcode 241] Different Ways to Add Parentheses
    [leedcode 240] Search a 2D Matrix II
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8306248.html
Copyright © 2011-2022 走看看