Small opCall problem

Philippe Sigaud philippe.sigaud at gmail.com
Sun May 30 09:21:29 PDT 2010


On Sun, May 30, 2010 at 17:04, bearophile <bearophileHUGS at lycos.com> wrote:

> struct Foo(T) {
>    this(T x) {}
>    void opCall(U)(U y) {}
> }
> void main() {
>    auto foo = Foo!int(1);
>    foo(1.5);
> }
>

I've had this one too. I think it's a bug, because foo is already
constructed when foo(1.5) is used. So the compiler should know it's an
opCall and not a constructor call.
The only solution I found was a kludge:


struct Foo(T)
{
   void initialize(T)(T x) {} // in my case, their was some data
initialization there.
   void opCall(U)(U y) {}
}

Foo!T foo(T)() { Foo!T f; f.initialize(); return f;}

void main() {
    auto f = foo(1);
   f(1.5);
}


Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100530/a3a761ac/attachment.html>


More information about the Digitalmars-d-learn mailing list