www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problem about using struct

reply "Tongzhou Li" <zhangsongcui hotmail.com> writes:
Hello! I'm learning D, and wrote some sample codes with D.
I wrote: http://ideone.com/VY7ES

It failed to compile; I got 2 errors:
     main.d(19): Error: constructor 
main.carry!(int,int,int,int,int).carry.this (int delegate(int, 
int _param_0, int _param_1, int _param_2) _f) is not callable 
using argument types (int)
     main.d(19): Error: cannot implicitly convert expression (1) 
of type int to int delegate(int, int _param_0, int _param_1, int 
_param_2)
Compiler used: DMD v2.059 (I used lambda expression which ideone 
doesn't support)

Don't know what it means, I don't call any constructor in Line 
19. Then I tried to use "class" instead of "struct" 
(http://ideone.com/ZI2Tn), it worked fine.

So what's wrong with that?
Sorry for my poor English:)
Jun 24 2012
next sibling parent reply "Kenji Hara" <k.hara.pg gmail.com> writes:
On Monday, 25 June 2012 at 06:05:34 UTC, Tongzhou Li wrote:
 Hello! I'm learning D, and wrote some sample codes with D.
 I wrote: http://ideone.com/VY7ES

 It failed to compile; I got 2 errors:
     main.d(19): Error: constructor 
 main.carry!(int,int,int,int,int).carry.this (int delegate(int, 
 int _param_0, int _param_1, int _param_2) _f) is not callable 
 using argument types (int)
     main.d(19): Error: cannot implicitly convert expression (1) 
 of type int to int delegate(int, int _param_0, int _param_1, 
 int _param_2)
 Compiler used: DMD v2.059 (I used lambda expression which 
 ideone doesn't support)

 Don't know what it means, I don't call any constructor in Line 
 19. Then I tried to use "class" instead of "struct" 
 (http://ideone.com/ZI2Tn), it worked fine.

 So what's wrong with that?
 Sorry for my poor English:)
Unfortunately, this is a dmd bug that yet not fixed. http://d.puremagic.com/issues/show_bug.cgi?id=6036 As far as I know, there is no workaround... Kenji Hara
Jun 25 2012
parent "Tongzhou Li" <zhangsongcui hotmail.com> writes:
On Monday, 25 June 2012 at 10:10:56 UTC, Kenji Hara wrote:
 On Monday, 25 June 2012 at 06:05:34 UTC, Tongzhou Li wrote:
 Hello! I'm learning D, and wrote some sample codes with D.
 I wrote: http://ideone.com/VY7ES

 It failed to compile; I got 2 errors:
    main.d(19): Error: constructor 
 main.carry!(int,int,int,int,int).carry.this (int delegate(int, 
 int _param_0, int _param_1, int _param_2) _f) is not callable 
 using argument types (int)
    main.d(19): Error: cannot implicitly convert expression (1) 
 of type int to int delegate(int, int _param_0, int _param_1, 
 int _param_2)
 Compiler used: DMD v2.059 (I used lambda expression which 
 ideone doesn't support)

 Don't know what it means, I don't call any constructor in Line 
 19. Then I tried to use "class" instead of "struct" 
 (http://ideone.com/ZI2Tn), it worked fine.

 So what's wrong with that?
 Sorry for my poor English:)
Unfortunately, this is a dmd bug that yet not fixed. http://d.puremagic.com/issues/show_bug.cgi?id=6036 As far as I know, there is no workaround... Kenji Hara
Well, that's too bad...
Jun 25 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Tongzhou Li:

 Don't know what it means, I don't call any constructor in Line 
 19. Then I tried to use "class" instead of "struct" 
 (http://ideone.com/ZI2Tn), it worked fine.

 So what's wrong with that?
At first sight your code seems OK. There is a well known compiler bug that makes it call the struct constructor instead of its opCall. I think there is already a pull request that fixes it in Bugzilla since some time (there are more than one hundred of those open). Bye, bearophile
Jun 25 2012