Why does templated interface function return something different than final function?
Timoses
timosesu at gmail.com
Wed Jul 18 11:29:55 UTC 2018
On Wednesday, 18 July 2018 at 11:09:12 UTC, Timoses wrote:
> Why is the interface templated function not also returning the
> class C toString return value "in C"??
>
> interface iface
> {
> void toString(scope void delegate(const(char)[]) sink) const;
>
> final string convert() inout
> {
> import std.conv;
> // assert(std.conv.to!string(this) == "in C"); // fails!
> return std.conv.to!string(this);
> }
>
> final string convert2() const
> {
> import std.conv;
> assert(std.conv.to!string(this) == "in C");
> return std.conv.to!string(this);
> }
> }
>
> class C : iface
> {
> void toString(scope void delegate(const(char)[]) sink) const
> {
> sink("in C");
> }
> }
>
> void main ()
> {
> iface i = new C();
> import std.stdio;
> writeln(i.convert); // "app.C"
> writeln(i.convert2()); // "in C"
> }
>
> It seems like `inout` triggers some odd behaviour??
Sorry, I experimented a bit and forgot to change the topic to
something more fitting, e.g.
"Why does inout struct function return different results?"
More information about the Digitalmars-d-learn
mailing list