Accessing a field of a containing class from within a nested class

Charles Hixson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 1 11:25:50 PDT 2015


The class Node is contained within the struct BTree.
The field   btFile is contained within the struct BTree.
The statement is within a function within the Node class.

I've tried many variations, here are a few:

btFile.write(self.nodeId, cast(void*)&(self));
results in:
need 'this' for 'btFile' of type 'BlockFile'

this.btFile.write(self.nodeId, cast(void*)&(self));
results in:
Error: no property 'btFile' for type 'btplus.BTree.Node'

this.BTree.btFile.write(self.nodeId, cast(void*)&(self));
results in:
  Error: constructor btplus.BTree.this (string fName) is not callable 
using argument types (Node)

Perhaps BTree needs to be a class?  I made it a struct because I want it 
to definitely close properly when it
goes out of scope.


More information about the Digitalmars-d-learn mailing list