zoukankan      html  css  js  c++  java
  • 多重继续的二义性总结

    1.多重继续的二义性,根本原因是

    假如A有Test(),则B和C都有Test(),于是D产生了二义性

    2.例1:


    3.对例1稍作改变,结果又会不同

    解释:

    编译器通常都是从离自己最近的目录树向上搜索的

    子类的Test()覆盖了基类的Test(),并不代表基类的Test()消失,只是不能直接访问

    3.令B公有继承于A,以下函数都是公有

    1)A有几个Test()的重载,B没有Test()

    则:b.Test()调用A相应的重载

    2)A有几个Test()的重载,B有Test()的重载1,没有Test()的重载2

    则:b.hello()重载1,则调用B的相应重载

            b.hello()重载2,则出错

            b.A::hello(),则调用A的相应重载

    4.对于单一继承,子类能否访问父类的父类,只与继承的方式有关

    对于多重继承,子类不能直接访问父类的父类。
     

    5.用virtual来避免二义性。

    class B : virtual public A.

  • 相关阅读:
    leetcode 279. Perfect Squares
    leetcode 546. Remove Boxes
    leetcode 312. Burst Balloons
    leetcode 160. Intersection of Two Linked Lists
    leetcode 55. Jump Game
    剑指offer 滑动窗口的最大值
    剑指offer 剪绳子
    剑指offer 字符流中第一个不重复的字符
    leetcode 673. Number of Longest Increasing Subsequence
    leetcode 75. Sort Colors (荷兰三色旗问题)
  • 原文地址:https://www.cnblogs.com/windmissing/p/2559873.html
Copyright © 2011-2022 走看看