struct in class feature
Rob T
rob at ucora.com
Tue Dec 11 17:36:43 PST 2012
On Tuesday, 11 December 2012 at 03:28:00 UTC, d coder wrote:
> Greetings
>
> I too find this very useful. I am also having this situation
> often when
> there is an array of nested struct instances inside a class
> environment.
> This is a common scenario and deserves attention. Also I
> believe (looking
> at D1 forums) that there was a time in the past when D1 nested
> structs did
> support 'outer'.
>
> But unfortunately structs are neglected part of D, so I am not
> sure if
> developers give an ear to this thread. To make D truly a
> systems language
> we need to make structs more robust and feature rich.
>
> Regards
> - Puneet
If I want to manually pass the parent pointer to a child struct,
how do I do it? The compiler won't allow me to use "this" from
the parent until after the parent has been instantiated.
The solution I came up with is to create a default constructor
for the parent that sets the child struct with the parents
pointer. It works but maybe there's a better way?
BTW, the same situation happens with structs defined inside
structs, they will not have access to the parent struct members
unless you manually pass a pointer into the child struct at some
point after the parent struct's address becomes known. You cannot
create a default constructor for a struct, so reliably
initializing the child struct with the parents pointer is
problematic.
--rt
More information about the Digitalmars-d
mailing list