interface function member declarations needing parameter attributes ?
Adam D Ruppe
destructionator at gmail.com
Sat Jul 17 22:48:00 UTC 2021
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.
More information about the Digitalmars-d-learn
mailing list