Re: What am I doing wrong here?

2022-05-08 Thread JG via Digitalmars-d-learn
On Saturday, 7 May 2022 at 02:29:59 UTC, Salih Dincer wrote: On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote: ```d //... struct Adder { int a; int opCall(int b) { return a+b; } } auto adder(int a) { auto ret = Adder.init; ret.a=a; return ret; } void main() { auto g =

Re: What am I doing wrong here?

2022-05-06 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote: ```d //... struct Adder { int a; int opCall(int b) { return a+b; } } auto adder(int a) { auto ret = Adder.init; ret.a=a; return ret; } void main() { auto g = adder(5); g(5).writeln; // 10 auto d = toDelegate!(int,

Re: What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
On Friday, 6 May 2022 at 18:35:40 UTC, Ali Çehreli wrote: On 5/6/22 11:04, JG wrote: > [...] This is a segmentation fault. Reduced: import std; [...] Hi, thanks. That was quite silly. (I was thinking the variable lives to the end of scope of main but not thinking about that I am passing

Re: What am I doing wrong here?

2022-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 5/6/22 11:04, JG wrote: > This isn't code to be used for anything (just understanding). This is a segmentation fault. Reduced: import std; struct Delegate(A,B) { B function(void* ptr, A a) f; void* data; B opCall(A a) { return f(data,a); } } auto toDelegate(A,

What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
This isn't code to be used for anything (just understanding). ```d import std; struct Delegate(A,B) { B function(void* ptr, A a) f; void* data; B opCall(A a) { return f(data,a); } } auto toDelegate(A, B,S)(S s) { static B f(void* ptr, A a) { return

What am I doing wrong here?

2012-10-14 Thread Martin
Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code snippet that's generating a forward reference error: public class AliasTestClass(alias func) {

Re: What am I doing wrong here?

2012-10-14 Thread Simen Kjaeraas
On 2012-10-14, 14:28, Martin wrote: Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code snippet that's generating a forward reference error: public class

Re: What am I doing wrong here?

2012-10-14 Thread Martin
On Sunday, 14 October 2012 at 12:58:24 UTC, Simen Kjaeraas wrote: On 2012-10-14, 14:28, Martin wrote: Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code