interface function member declarations needing parameter attributes ?

someone someone at somewhere.com
Sat Jul 17 22:59:10 UTC 2021


On Saturday, 17 July 2021 at 22:48:00 UTC, Adam D Ruppe wrote:
> On Saturday, 17 July 2021 at 22:43:15 UTC, someone wrote:
>> So the lesson learned is that interfaces can also mandate 
>> member function's parameter attributes then ... right ?
>
> A subclass must accept anything the parent class can, but it 
> can also make it stricter if you want.
>
> class Base {
>         void foo(Object o) {}
> }
>
> class Derived : Base {
>         override void foo(const Object o) {}
> }
>
>
> That's legal because const also accepts mutable. Derived is 
> stricter than Base which is permitted. But the other way around:
>
> class Base {
>         void foo(const Object o) {}
> }
>
> class Derived : Base {
>         override void foo(Object o) {}
> }
>
> is NOT allowed because the mutable thing in derived cannot be 
> passed back to the base interface implicitly.

Perfectly clear; thanks Adam :) !



More information about the Digitalmars-d-learn mailing list