www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opCall override default constructor?

reply Jacob Carlborg <doob me.com> writes:
Is it intentional that a non-static opCall overrides the default 
constructor of a struct?

struct Foo
{
     int a;

     void opCall(string b) { }
}

void main()
{
     auto f = Foo(3); // line 14
     f("asd");
}

The above code gives the following error:

main.d(14): Error: function main.Foo.opCall (string b) is not callable 
using argument types (int)

-- 
/Jacob Carlborg
Jun 02 2016
next sibling parent Era Scarecrow <rtcvb32 yahoo.com> writes:
On Thursday, 2 June 2016 at 08:50:26 UTC, Jacob Carlborg wrote:
 Is it intentional that a non-static opCall overrides the 
 default constructor of a struct?

     auto f = Foo(3); // line 14

 main.d(14): Error: function main.Foo.opCall (string b) is not 
 callable using argument types (int)
It sounds like a bug, since the object isn't instantiated yet it shouldn't be able to call opCall yet...
Jun 02 2016
prev sibling parent reply Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
On Thursday, 2 June 2016 at 08:50:26 UTC, Jacob Carlborg wrote:
 Is it intentional that a non-static opCall overrides the 
 default constructor of a struct?

 struct Foo
 {
     int a;

     void opCall(string b) { }
 }

 void main()
 {
     auto f = Foo(3); // line 14
     f("asd");
 }

 The above code gives the following error:

 main.d(14): Error: function main.Foo.opCall (string b) is not 
 callable using argument types (int)
It's this bug: https://issues.dlang.org/show_bug.cgi?id=9078
Jun 02 2016
parent Jacob Carlborg <doob me.com> writes:
On 2016-06-02 12:16, Marc Schütz wrote:

 It's this bug:
 https://issues.dlang.org/show_bug.cgi?id=9078
Ok, thanks. -- /Jacob Carlborg
Jun 02 2016