D - BUG? - struct initialization
- Paul Runde (22/22) Mar 25 2004 This compiles:
- Derek Parnell (10/31) Mar 25 2004 Hmmmm... probably shouldn't have compiled as there is no constructor tha...
- Walter (3/25) Mar 25 2004 It shouldn't compile. -Walter
This compiles: struct foo { int x; void opCall(int a) { x = a; printf("%d\n", x); } } int main(char[][] args) { foo* f = new foo(3); printf("%d\n", f.x); (*f)(5); return 0; } Output is: 0 5 Should this compile? Or should have f.x been initialized to 3? Thanks
Mar 25 2004
On Thu, 25 Mar 2004 18:26:24 -0600 (26/Mar/04 11:26:24 AM) , Paul Runde <prunde consolidated.net> wrote:This compiles: struct foo { int x; void opCall(int a) { x = a; printf("%d\n", x); } } int main(char[][] args) { foo* f = new foo(3); printf("%d\n", f.x); (*f)(5); return 0; } Output is: 0 5 Should this compile? Or should have f.x been initialized to 3?Hmmmm... probably shouldn't have compiled as there is no constructor that matches 'this(int)', which is what should have been invoked by the 'new foo(3)' statement. Certainly the opCall function should not have been called at construction time. -- Derek -- Derek
Mar 25 2004
It shouldn't compile. -Walter "Paul Runde" <prunde consolidated.net> wrote in message news:c3vt95$2rk1$3 digitaldaemon.com...This compiles: struct foo { int x; void opCall(int a) { x = a; printf("%d\n", x); } } int main(char[][] args) { foo* f = new foo(3); printf("%d\n", f.x); (*f)(5); return 0; } Output is: 0 5 Should this compile? Or should have f.x been initialized to 3? Thanks
Mar 25 2004