Date: Tue, 17 Mar 2020 20:49:21 +0200
On Tue, 17 Mar 2020 at 20:12, Ryan Nicholl via Std-Proposals
<std-proposals_at_[hidden]> 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?
>
> Suggestion, specific override specifier:
>
> virtual int lock_mutex() override(int B::lock());
> virtual int lock_device() override(int C::lock());
struct BWrap : B
{
int lock() override final {lock_mutex();}
virtual int lock_mutex();
};
struct CWrap : C
{
int lock() override final {lock_device();}
virtual int lock_device();
};
class A : public BWrap, public CWrap
{...};
The need to do this, considering that you can work around it as the
author of A, doesn't seem to be common
enough to justify a built-in language facility for it. If the
boilerplate bothers you, wait until reflection+injection
lands.
<std-proposals_at_[hidden]> 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?
>
> Suggestion, specific override specifier:
>
> virtual int lock_mutex() override(int B::lock());
> virtual int lock_device() override(int C::lock());
struct BWrap : B
{
int lock() override final {lock_mutex();}
virtual int lock_mutex();
};
struct CWrap : C
{
int lock() override final {lock_device();}
virtual int lock_device();
};
class A : public BWrap, public CWrap
{...};
The need to do this, considering that you can work around it as the
author of A, doesn't seem to be common
enough to justify a built-in language facility for it. If the
boilerplate bothers you, wait until reflection+injection
lands.
Received on 2020-03-17 13:52:21