Date: Tue, 17 Mar 2020 23:01:34 -0700
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?
> 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
Received on 2020-03-18 01:04:24