How do i depend on struct composition
JS
js.mdnq at gmail.com
Thu Aug 22 16:53:19 PDT 2013
On Thursday, 22 August 2013 at 23:10:40 UTC, anonymous wrote:
> On Thursday, 22 August 2013 at 22:32:53 UTC, JS wrote:
>> On Thursday, 22 August 2013 at 21:07:27 UTC, Mariusz `shd`
>> Gliwiński wrote:
> [...]
>>> struct InnerC
>>> {
>>> void operate()
>>> {
>>> auto ptr = this-(void*).sizeof;
>>> /* do something with pointer */
>>> }
>>> }
>>>
>>> struct Compound(Inner)
>>> {
>>> Inner a_or_b;
>>> InnerC c;
>>> }
> [...]
>> If you actually nest InnerC inside Compound then it will
>> contain a pointer(using this) to the parent. You can then use
>> `parent` inside `operator` to access the parent which can
>> access a_or_b.
>
> I think you're thinking of nested classes[1] here.
> Nested structs[2] are a little different. A nested struct is
> associated with a function, not with another struct.
> (By the way, I guess you mean `outer` instead of `parent`.)
>
> [1] http://dlang.org/class.html#nested
> [2] http://dlang.org/struct.html#nested
Your right, I don't know why there isn't an equivalent for
structs. In any case, check out
http://dpaste.dzfl.pl/7f086694
and
http://www.digitalmars.com/d/archives/digitalmars/D/Nested_Structs_183295.html
for a solution
More information about the Digitalmars-d-learn
mailing list