[Understanding] Classes and delegate inheritance vs function pointers
Steven Schveighoffer
schveiguy at gmail.com
Sun Jan 10 14:17:32 UTC 2021
On 1/9/21 3:20 PM, Q. Schroll wrote:
> Yes. Actually, I need it for slices, but only pointer part of it really
> mattered.
>
> A Derived[] is implicitly a const(Base)[], not a Base[].
> A void delegate() @safe[] is implicitly a const(void delegate())[].
> But it seems a void function() @safe[] **isn't** implicitly a const(void
> function())[].
>
> Functions taking those are kind of useless like that.
It should work. The reason const works is under the theory that you
cannot change it, so there is no danger of replacing the value with
something that isn't the original type.
I would say as long as it's covariant (or contravariant? I can't
remember), implicit casting to a const array should work.
-Steve
More information about the Digitalmars-d-learn
mailing list