0

Say I have an inherited class with function A and B. B does something and call A. Base class also have function A and B. B does the thing in a different way and then call A (the derived class's A). However in a specific situation I want to call the base class's B. This is done using Base::B(). Then B will call A, my question is, which A will it call? The base one or the inherited one?

parkydr
  • 7,596
  • 3
  • 32
  • 42
jazzybazz
  • 1,807
  • 4
  • 17
  • 21

2 Answers2

2

It depends whether A is virtual or not. If virtual the derived version will be called, if not it will be the base version.

parkydr
  • 7,596
  • 3
  • 32
  • 42
0

You are proposing a generic scenario here, but it's enough to determine that you are referring to the MRO, aka Method Resolution Order, which is the algorithm ( or the class of algorithms, you can use this acronym to refer to a general topic or a specific single thing ) used to determine which method needs to be called.

How the MRO works in the C++ case it's described in the standard itself, but there is a dedicated tag here on SO named method-resolution-order and an answer that can give you a broad view about this.

Community
  • 1
  • 1
user2244984
  • 449
  • 4
  • 11