Implicit type conversion for function calls?

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 10 08:20:02 PDT 2011


On Sun, 10 Jul 2011 16:41:17 +0200, bearophile <bearophileHUGS at lycos.com>  
wrote:

> There is a uncommon syntax that allows you to do it with a class, but I  
> don't know why structs don't work here:
>
> class Foo {
>     int data;
>
>     this(int n) {
>         data = n;
>     }
> }
>
> void bar(Foo f ...) {
>     assert(f.data == 3);
> }
>
> void main() {
>     bar(3);
> }

Smells like a bug. But, even if that did work for structs, it is an
invasive way to do it, which opImplicitCastTo/From would not be.

For a typedef template, that's unacceptable.

-- 
   Simen


More information about the Digitalmars-d-learn mailing list