C++:去虚拟化叶子类 [英] C++: Devirtualize Leaf Classes

查看:38
本文介绍了C++:去虚拟化叶子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java、C# 和 D 等语言中,finalsealed 类保证是叶类(没有其他类继承自的类).这允许编译器对编译时类型为 finalsealed 的对象进行顶级 devirtualize 方法调用.

In languages like Java, C# and D, final or sealed classes are guaranteed to be leaf classes (classes that no other class inherits from). This allows the compiler top devirtualize method calls to objects whose compile-time type is final or sealed.

C++ 没有 finalsealed 关键字.有没有什么方法可以模拟它在继承层次结构中作为叶子的类的去虚拟化的行为?

C++ does not have a final or sealed keyword. Is there any way to simulate its behavior with regard to de-virtualization of classes that are leafs in my inheritance hierarchy?

推荐答案

C++11 确实有 final,虽然它是一个特殊标识符,而不是一个关键字.它不服务于去虚拟化"的目的.它只是防止派生自类或防止派生类中覆盖单个方法.

C++11 does have final, although it is a special identifier, not a keyword. It does not serve a "devirtualization" purpose. It simply prevents classes being derived from or single methods being overriden in derived classes.

这篇关于C++:去虚拟化叶子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆