Implicit conversion by return

Alex sascha.orlov at gmail.com
Wed Aug 8 08:44:03 UTC 2018


On Wednesday, 8 August 2018 at 08:15:16 UTC, Hakan Aras wrote:
> Given this:
>
> struct Num
> {
>     this(int a) {}
> }
>
> Is there any reason why this works:
>
> Num n = 5;
>
> but this doesnt:
>
> Num funk()
> {
>     return 5;
> }
>
>
> I understand that I can construct it explicitely, but that gets 
> annoying quickly, especially with templates.

I suppose, this is too slack.

What would work is

Num funk()
{
     return typeof(return)(5);
}


More information about the Digitalmars-d-learn mailing list