[Issue 9078] non-static opCall is chosen instead of a default constructor

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Oct 3 00:00:55 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=9078

monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com

--- Comment #3 from monarchdodra at gmail.com ---
I just hit this again today. It's pretty bad, and it's not very clear either
what is going on. Can we do anything to fix this.

In particular, I was writting a "functor" style object, but with an opCall that
takes no arguments. The reduced example is:

struct A
{
    int opCall()
    {
    }
}

void main() {
    auto a = A(); // !!!
}

Using "A()" fails to compile.

In particular, once you've defined the opCall, it simply becomes *impossible*
to declare an instance of your struct, unless you define a constructor, or use
A.init.

That's all pretty bad.

--


More information about the Digitalmars-d-bugs mailing list