TSG
TSG

Reputation: 4617

Preventing descendants from overriding method

In C++ (11/14/17, I don't care), I have a base class B which exposes method x as protected.

In class D1, which derives from B, I want to prevent further descendants (of D1) from calling x(). Now, if I were overriding x in D1, I would simply mark it as final.

But, what if D1 does not override x(), yet D1 still wants to hide it from descendants? How can I do that?

Upvotes: 0

Views: 88

Answers (1)

eerorika
eerorika

Reputation: 238281

How can I do that?

By changing the program and overriding x in D1. You can just delegate to the base class version by calling it.

Upvotes: 1

Related Questions