jazzybazz
jazzybazz

Reputation: 1887

Inheritance, hiding functions, and scopes c++

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?

Upvotes: 0

Views: 58

Answers (2)

user2244984
user2244984

Reputation: 469

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.

Upvotes: 0

parkydr
parkydr

Reputation: 7784

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

Upvotes: 2

Related Questions