C++ static binding and dynamic binding

static binding and dynamic binding

1. Binding refers to the process of interrelatedness between a program module and code.
2. Static binding (static binding) is the realization of program matching and connection in the compilation stage, also known as early matching.
Overloaded functions use static binding.
3. Dynamic binding means that program binding is delayed until runtime, so it is also called late binding (late binding).
Switch statements and if statements are examples of dynamic binding.

1. C++ is the same as C. It is a static compiled language
. 2. When compiling, the compiler automatically determines what kind of object it points to according to the type of the pointer; so the compiler thinks that the parent class pointer points to the parent class object.
3. Since the program is not running, it is impossible to know whether the parent class pointer points to the parent class object or the child class object.
From the perspective of program safety, the compiler assumes that the parent class pointer only points to the parent class object, so the result of compilation is to call the parent class object. member functions of the class. This feature is static binding.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325485655&siteId=291194637