C++研究笔记(1)动态类型和静态类型

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

C++ 标准明确定义:

1.3.3 dynamic type [defns.dynamic.type]

the type of the most derived object (1.8) to which the lvalue denoted by an lvalue expression refers.

The dynamic type of an rvalue expression is its static type.

动态类型的定义是:由一个左值表达式指出的左值的动态类型,是其所引用的对象的最狭义类型。一个右值表达式的动态类型,就是它的静态类型。

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 executing.

静态类型,是指不需要考虑表达式的执行期语义,仅从表达式的字面的形式就能够决定的类型。静态类型在程序运行时不会改变。

通常我们说,“基类指针指向的对象的实际/真正类型”或“基类引用所引用的对象的实际/真正类型”,就是它们的动态类型。很显然,这个动态类型是 C++ 语言通过指针和引用实现运行时多态能力的核心概念。

我将在考虑有关左值和右值的概念时继续对动态类型和静态类型的语义逻辑进行分析。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航