struct in class access

Jonathan M Davis jmdavisProg at gmx.com
Sat Dec 8 23:24:06 PST 2012


On Sunday, December 09, 2012 07:54:25 js.mdnq wrote:
> Why can't a struct inside a class access the members of that
> class without a this pointer? It would seem natural to me that a
> nested struct should probably be special in that it is really
> just a special container to reduce clutter in the class.

Without a this pointer, there are no class members to access, because they 
have to be associated with a specific instance of the class unless they're 
static. Non-static, nested structs have access to their enclosing scope, but 
then you can't create them separate from the enclosing class. However, if you 
declare a nested class to be static, it has no access to the class' members 
and is not associated with a specific instance of the class. It's just that 
it's declared inside the class instead of outside of it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list