Re: Best way to reference an array in a child class...

2014-03-07 Thread captain_fid
On Friday, 7 March 2014 at 13:57:31 UTC, Steven Schveighoffer wrote: On Thu, 06 Mar 2014 17:44:09 -0500, captain_fid wrote: this() {items = [ {10, "first"}, {20, "second"}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was

Re: Best way to reference an array in a child class...

2014-03-07 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 17:44:09 -0500, captain_fid wrote: this() {items = [ {10, "first"}, {20, "second"}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was no real issue. I thought using a static array of structs in the chi

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Friday, 7 March 2014 at 00:10:20 UTC, bearophile wrote: captain_fid: struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A { this() {items = [ {10, "first"}, {20, "second"}];}// line 21 override void doit() { } } (21): Error: found '}' when

Re: Best way to reference an array in a child class...

2014-03-06 Thread bearophile
captain_fid: struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A { this() {items = [ {10, "first"}, {20, "second"}];}// line 21 override void doit() { } } (21): Error: found '}' when expecting ';' following statement (21): Error: found '

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Well, actually... take it back. When I did try this syntax, I receive(d) the following error. I then went and created this test which I thought couldn't go wrong. with both dmd and gdc ... struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A {

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
this() {items = [ {10, "first"}, {20, "second"}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was no real issue. I thought using a static array of structs in the children would be more efficient when instantiating the objec

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 22:16:50 UTC, Steven Schveighoffer wrote: On Thu, 06 Mar 2014 17:05:12 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 02:05 PM, captain_fid wrote: > Your suggestion Ali (of not accessing the base member in the child was > great) and it works properly. > > Believe if I understand what you are suggesting above is never to have > the array in base? simply retrieve slice through the child member funct

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 17:05:12 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have anothe

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have another copy in the child class :) Agreed. Alternatively,

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have another copy in the child class :) Agreed. Alternatively, a member function in the child class could return a slice. Ali

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Steve and Ali, Thanks for the quick helpful suggestions. In this case I probably don't need the expansion (but certainly look forward to understanding either way). I'll certainly hit that reference (Special thanks Ali for your book. I've enjoyed it over the past few months)

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 15:02:14 -0500, Steven Schveighoffer wrote: Second, it's very difficult to get an array, just by itself, in the heap. And you don't want to store a reference to a stack-frame slice. Sorry, I meant an array *reference*, not an array. Clearly allocating an array in the

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
doesn't understand what a D slice is. Actually, given the subject of this post, I take it back. The best way to reference an array in a child class, especially one of a static type, is to not have another copy in the child class :) > You can read more about D arrays and sli

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:40 AM, Steven Schveighoffer wrote: >> class A >> { >>S[]* pointer_to_list; >>abstract... >> } > I would highly suggest to just use S[] and not S[]*. A slice is already > a reference (coupled with a length). But what if there are elements added to B.items later on? I ass

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 14:31:52 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:31 AM, captain_fid wrote: On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct S { int a;

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct S { int a; string b; } class A { S[]* pointer_to_lis

Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S {