January 10, 2005 Nested struct array question.. | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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: A a=new 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=new 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. |
January 13, 2005 Re: Nested struct array question.. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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/ |
Copyright © 1999-2021 by the D Language Foundation