[Understanding] Classes and delegate inheritance vs function pointers
Q. Schroll
qs.il.paperinik at gmail.com
Sat Jan 9 18:16:04 UTC 2021
Say I have a class hierarchy like this:
class Base { }
class Derived : Base { }
A Derived object cannot be referenced as a Base object, but as a
const(Base) object. That makes sense to me.
One can replace Base by a @system delegate type (SysDG) and
Derived by a @safe delegate type (SafeDG) and it works the same
way: a SafeDG object cannot be referenced as a SysDG object, but
as a const(SysDG) object.
However, if I try that with function pointers instead of
delegates (SysFP, SafeFP), for some reason, a SafeFP cannot be
referenced as a const(SysFP).
This makes no sense in my head. Is there some reason I'm unable
to see?
Example code is here: https://run.dlang.io/is/zSNArx
More information about the Digitalmars-d-learn
mailing list