What's the rationale here? alias this and function arguments

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 10 03:27:13 PDT 2015


struct S
{
	int a;
	this(T)(T v)
	{
		this = v;
	}
	void foo(T)(T v)
	{
		import std.conv : to;
		a = v.to!int;
	}
	alias foo this;
}

void bar(S s){}

void main()
{
	S s0;
	s0 = "3"; //OK
	S s = "3"; //OK
	bar("3"); //Not OK
}

It would seem logical that the last one would work as well. 
What's the reasoning behind this?


More information about the Digitalmars-d-learn mailing list