digitalmars.D - Nested struct array question..
- Jarrett Billingsley (35/35) Jan 09 2005 charset="iso-8859-1"
-
Simon Buchan
(13/15)
Jan 13 2005
On Sun, 9 Jan 2005 21:17:07 -0500, Jarrett Billingsley
charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Say you have a class with a struct inside, like so: class A { struct B { int fork() { return 5; } } } You can then access B's members using:=20 A a=3Dnew A; writefln(a.B.fork()); This is fine. However, if I want to have an array of nested structs.. class A { struct B { int fork() { return 5; } } B[5] b; } You can easily access this array as you would expect: A a=3Dnew A; writefln(a.b[0].fork()); But you can still access the class definition: writefln(a.B.fork()); Normally in C++, I'd use the struct{...} b[5]; syntax, but that isn't = available in D. I've also tried to make the struct private (and yes, the class is in a = separate module), and I can still access it. Is there any way to have an array of nested structs without being able = to access the definition? Putting the struct outside the class is not = possible, as the struct depends upon access to the class's methods.
Jan 09 2005
On Sun, 9 Jan 2005 21:17:07 -0500, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote: <snip>Normally in C++, I'd use the struct{...} b[5]; syntax, but that isn't available in D.<snip> Can't say how many times I've wanted that syntax, but throwing out the ; after structs has throwen the baby out too, as it were. Unfortunatley I can't help with the rest of that, unless struct {...}[5] b; works for you (You loose the namespace scope, though) (If you really can still access it, post it in digitalmars.D.bugs) -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jan 13 2005