C ++ research note (1) Dynamic type and static type

xiaoxiao2021-03-06  114

C standards are clearly defined:

1.3.11 Static Type [Defns.Static.Type]

the type of an expression (3.9), which type results from analysis of the program without considering execution semantics. The static type of an expression depends only on the form of the program in which the expression appears, and does not change while the program is The static type refers to the expression type that does not need to consider the execution period semimony, only the type of expression determined by only program text. Static types only depend on the form of program text that contains expressions, and will not change when the program is running.

1.3.3 Dynamic Type [Defns. Dynamic.Type]

To which the Lvalue Denoted by An Lvalue Expression ReferS. D, Derived from B (CLAUSE 10), The Dynamic Type of The Expression * P IS "D." References (8.3.2) Are Treated Similarly.] The Dynamic Type of An Rvalue Expression is its static type. Dynamic Type is: The type of final derived object referenced by the left value represented by a left value expression. [Example: If a pointer (8.3.1) P in a static type "class B" is pointing to an object inherited to class D in B (chapter 10), the dynamic type of expression * P is "D". The reference (8.3.2) is processed according to similar rules. 】 A dynamic type of a right expression is its static type.

Usually we said that "the actual / real type" or "actual / real type" or "base class reference references" is the actual / real type of object referenced by the base class, is its dynamic type. Obviously, this dynamic type is the core concept of C language through pointers and references to achieve runtime polymorphism.

转载请注明原文地址:https://www.9cbs.com/read-100158.html

New Post(0)