C++ Logo

std-proposals

Advanced search

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

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 05 Jan 2023 22:14:34 +0000
On 5 January 2023 21:56:30 GMT, 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; }
>};
>
>However it's currently not permissible to mark a non-virtual member
>function as 'final'.
>
>Can we change this?

"Name hiding" and "overriding" are fundamentally different mechanisms. This feature would just confuse them further.

Note that currently you can hide a base member function (even a final virtual one) with a derived member function with different signature but same name.

Cheers,
Lénárd

Received on 2023-01-05 22:14:43