overriding with difference access specification c++

后端 未结 4 1838

I came across a question while taking iKM test. There was a base class with two abstract methods with private access specifier. There was a derived class which was overridin

4条回答
  •  悲&欢浪女
    2020-12-11 18:27

    It is allowed, in both directions (ie, from private to public AND from public to private).

    On the other hand, I would argue it does not break the IS-A relationship. I base my argument on 2 facts:

    • using a Base& (or Base*) handle, you have exactly the same interface as before
    • you could perfectly (if you wish) introduce a forward method that is public and calling the private method directly anyway: same effect with more typing

提交回复
热议问题