Re: How to implement anonymous classes? (VBDis)
31 Oct 2003 23:07:47 -0500

          From comp.compilers

Related articles
How to implement anonymous classes? (Matthias Mann) (2003-10-27)
Re: How to implement anonymous classes? (2003-10-31)
| List of all articles for this month |

From: (VBDis)
Newsgroups: comp.compilers
Date: 31 Oct 2003 23:07:47 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG
References: 03-10-115
Keywords: OOP
Posted-Date: 31 Oct 2003 23:07:47 EST

Matthias Mann <> schreibt:

>Now my question is how to implement access to the member variables of
>the containing class

IMO you should think about "containing". Regardless of anonymous or
named declarations, a type declaration in some namespace only affects
the visibility of that declaration, but does not establish any
connection between elements in that same namespace. At runtime you
have multiple distinct objects (instances) of both classes.

You'll have the same problem with named local classes: when one object
has to refer to members of another object, then it needs a reference
to that other object. Also consider the general case, with multiple
nested local classes. Then the instances of the inner classes need
references to every single outer instance, since at runtime all these
are different and independent instances of various class types.

You can implement a "container" property in the local classes, which
is initialized during the construction of instances of the "contained"
(local) classes, either implicitly or (simpler) explicitly. Then the
instances of the inner classes can reference all levels of containing
classes, like with "container.container.myString". But I really don't
like such a construct, where changes in the subclass level will break
existing code. Instead I'd implement explicit direct references to all
objects, which the "contained" classes want to reference. Just the
well known traditional way...


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.