How do i depend on struct composition

anonymous anonymous at example.com
Thu Aug 22 16:10:39 PDT 2013


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


More information about the Digitalmars-d-learn mailing list