C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow non-virtual methods to be final

From: Brian Bi <bbi5291_at_[hidden]>
Date: Thu, 5 Jan 2023 17:00:54 -0500
On Thu, Jan 5, 2023 at 4:56 PM Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> The following should be allowed:
>
> struct A {
> int Func(void) final { return 5; }
> };
>
> in order to prevent the following from compiling:
>
> struct B : A {
> int Func(void) { return 6; }
> };
>

No.

There's no legitimate reason to restrict what the author of B can make one
of its non-virtual functions do. As such, there should not be a
language-level mechanism for it.


>
> However it's currently not permissible to mark a non-virtual member
> function as 'final'.
>
> Can we change this?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
*Brian Bi*

Received on 2023-01-05 22:01:08