C++ Logo


Advanced search

Subject: Re: [std-proposals] Specific Override Specifier
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-03-17 13:49:21

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

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

Standard Proposals Archives on Google Groups