Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:42:13 UTC, Ali Çehreli wrote: Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values: struct S { int i; string s; } void main() { auto s = new S(42); static assert(is (typeof(s) =

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:38 PM, Danyal Zia wrote: > You can initialize in constructor this(), but you can't initialize > partial fields of struct when using pointer to struct. Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values: st

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:32:48 UTC, seany wrote: do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment? You can initialize in constructor this(), but you can't initialize partial field

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:32 PM, seany wrote: > do I have to initialize all variables of the struct? No. The uninitialized ones get their .init values. > or may I also use a > this(){} in the struct and initialize only those which are known at a > given moment? That already works with structs. You don'

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:19 PM, seany wrote: > On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: >> On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: >>>arc!(string, string[]) * a; >>>a.some_var = "hello"; >> "a" has not been instantiated. You are declaring it as a pointer to >

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment?

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:19:28 UTC, seany wrote: For reasons further down in the software, I need to do this with a pointer. How do I do it with a pointer, please? I don't know what are you trying to achieve, but if that's what you want, you can do: void MYfunction() { auto strArr

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[]) * a; a.some_var = "hello"; } } void main() {

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Also, (*c).MYfunction() is leading to segmentation fault

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
sorry, I meant (*a).some_var not (*c).MYfunction()

struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[]) * a; a.some_var = "hello"; } } void main() { c = new myclass(); c.MYfunction(); } This leads to a