Subject: Re: [std-proposals] Specific Override Specifier
From: Joe Mucchiello (jmucchiello_at_[hidden])
Date: 2020-03-18 15:01:07
>Date: Tue, 17 Mar 2020 18:12:32 +0000
>From: Ryan Nicholl <rnicholl_at_[hidden]>
>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());
I would suggest a better syntax would reuse the = operator as used in constructors now:
virtual int lock_mutex() = int B::lock();virtual int lock_device() = int C::lock();
Not a complete solution, so this might also be needed:
virtual int lock() = delete;
A* a;a->lock_mutex(); // calls B::lock()a->lock_device(); // calls C::lock()a->lock(); Â Â // compiler error, attempted to call deleted virtual function.
(static_cast<B*>(a))->lock(); // calls B::lock(), as usual
The next problem is "can you delete virtual functions from parent classes even if there is no conflict?" I don't know. Would it be a bad thing? I don't think so. And making sure conflicting function names are not called accidentally can only be a good thing. But I'm not a compiler developer.
STD-PROPOSALS list run by herb.sutter at gmail.com
Standard Proposals Archives on Google Groups