mismatched function return type inference of string and double

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 3 15:22:54 PDT 2014


On Sunday, 3 August 2014 at 22:01:23 UTC, matt wrote:
> auto value(Parent item, int type)
> {
> 	if(item.type == 1)
> 	{
> 		return Fun!double(cast(Child!double)item);

Here you're returning a double.

> 	}
> 	else if(item.type==2)
> 		return Fun!string(cast(Child!string)item);

Here you're returning a string.

You're trying to return different, incompatible types depending
on runtime data (`type`). That's not possible. The return type
must be known at compile time.


More information about the Digitalmars-d-learn mailing list