Implicit Conversions in Struct Construction

Ali Çehreli acehreli at yahoo.com
Thu Oct 18 20:55:12 PDT 2012


On 10/18/2012 08:44 PM, Michael wrote:

 > auto fib(T = int)() if (isIntLike!T) {
 > struct Fib {
 > T a, b;

// ...

 > return Fib(0, 1);
 > }
 >
 > This code does not work if I call fib!BigInt(). The compiler complains
 > that 0 cannot be implicitly converted into a BigInt. It is right of
 > course, but BigInt has a constructor accepting a long, so shouldn't this
 > work anyway? What is the correct way to write this function?

Explicit conversion works:

     return Fib(T(0), T(1));

Ali



More information about the Digitalmars-d-learn mailing list