尧图精选

glvalue的 ‘动态类型’ 和 ‘静态类型’ ,‘多态’

🕒 发布时间:2026/9/8 13:02:43 📁 来源:尧图网络
在 C / value category 语境里这几个词常用英文是| 中文 | 英语 ||—|—|| 动态类型 |dynamic type|| 静态类型 |static type|| 多态 |polymorphism|| 多态的 |polymorphic|| 多态类型 |polymorphic type|| glvalue |glvalue全称generalized lvalue|例句1. 动态类型 / 静态类型Base*pnewDerived;可以说The static type of*pisBase, while its dynamic type isDerived.中文*p的静态类型是Base而它的动态类型是Derived。2. 多态structBase{virtualvoidf();};structDerived:Base{voidf()override;};可以说Baseis a polymorphic type because it has a virtual function.中文Base是一个多态类型因为它有虚函数。C 标准语境里的表达在讨论 glvalue 时经常会看到类似说法A glvalue has an identity and may have a dynamic type.中文大意glvalue 有身份标识并且可能具有动态类型。再比如If a glvalue refers to a polymorphic object, its dynamic type may differ from its static type.中文如果一个 glvalue 指代一个多态对象它的动态类型可能不同于它的静态类型。简单理解static type编译器在编译期看到的类型dynamic type程序运行时对象真正的类型polymorphism通过基类指针/引用调用派生类行为的机制polymorphic type有至少一个虚函数的类类型例如structBase{virtual~Base()default;};structDerived:Base{};Baseref*(newDerived);这里ref的static type是Baseref绑定对象的dynamic type是DerivedBase是polymorphic type一句话记忆static type 编译器看到的类型dynamic type 运行时真实对象类型polymorphism 多态。
上一篇/下一篇内容由系统自动关联 返回资讯列表 →