Why does templated interface function return something different than final function?

Timoses timosesu at gmail.com
Wed Jul 18 11:09:12 UTC 2018


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??


More information about the Digitalmars-d-learn mailing list