C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Specific Override Specifier
From: Thiago Macieira (thiago_at_[hidden])
Date: 2020-03-18 01:01:34


On Tuesday, 17 March 2020 11:12:32 PDT Ryan Nicholl via Std-Proposals wrote:
> Consider:
>
> class A : public B, public C
> {
> virtual int lock();
> };
>
> what happens if both B::lock and C::lock exist as virtual functions? we can
> override them both with one function... but what if they are interfaces
> that do different things and happen to use the same name?

Then you have an API design problem and it should be solved at that level.

C++ only allows one override per name and the function must have a single
functionality. This function is unlikely to be the same clash. Most likely,
you should not have multiply-inherited from both B and C.

> Suggestion, specific override specifier:
>
> virtual int lock_mutex() override(int B::lock());
> virtual int lock_device() override(int C::lock());

How would that look for a class derived from A? Would it now override as
lock_mutex() and lock_device()?

And what does a->lock() do?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups