__super

Myth丶恋晨 2022-08-05 04:25 226阅读 0赞
  1. __super::member_function();
  2. The __super keyword allows you to explicitly state that you are calling a base-class implementation for a function that you are overriding. All accessible base-class methods are considered during the overload resolution phase, and the function that provides the best match is the one that is called.
  3. struct B1 {
  4. void mf(int) {
  5. // ...
  6. }
  7. };
  8. struct B2 {
  9. void mf(short) {
  10. // ...
  11. }
  12. void mf(char) {
  13. // ...
  14. }
  15. };
  16. struct D : B1, B2 {
  17. void mf(short) {
  18. __super::mf(1); // Calls B1::mf(int)
  19. __super::mf('s'); // Calls B2::mf(char)
  20. }
  21. };
  22. int main() {
  23. }
  24. 这样子成员函数可以调用父的成员函数而不需要写父类名称,这是vs编译器特有的,gcc是不支持的。

发表评论

表情:
评论列表 (有 0 条评论,226人围观)

还没有评论,来说两句吧...

相关阅读

    相关 super关键字

    super `super`关键字的用法和this关键字的使用方法相似 1.`this`:代表本类对象的引用 2.`super`:代表父类存储空间的标识(可以理解为

    相关 super关键字

    Super关键字的使用 1. Super关键字 1.1 super可以理解为父类的关键字,super可以用来调用属性、方法、构造器 2. Super关键字的使用

    相关 super关键字

    (1)子类继承父类所有的成员变量和成员方法,但不继承父类的构造方法。在子类的构造方法中可使用语句 super(参数列表) 调用父类的构造方法。 建立Person类

    相关 extends super

    java的一个设计理念是,与泛型相关的异常最好是在编译期间就被发现,因此设计了extends与super这两种方式。 具体来说,List<? extends T>表示该集合

    相关 super关键字

    super关键字的使用 1.super理解为:父类的 2.super可以用来调用:属性、方法、构造器 3.super的使用:调用属性和方法 3.1 我们可以在子类的