Inner classes question
Ary Manzana
asterite at gmail.com
Mon Sep 11 05:23:54 PDT 2006
Ivan Senji wrote:
> Steve Horne wrote:
>> On Sun, 10 Sep 2006 13:11:47 +0200, Ivan Senji
>> <ivan.senji_REMOVE_ at _THIS__gmail.com> wrote:
>>
>>> I2 doesn't have a base class, so that wouldn't work.
>>
>> Yeah, I'm confusing myself.
>>
>> The problem, I suspect, is putting 'new' in an initialiser. If it was
>> in a (dynamic) method,
>
> Sorry (a bug in my example, but it doesn't change anything)
>
> class O
> {
> class I1
> {
> }
> class I2
> {
> this()
> {
> I1 a = new I1; //line 10 -> same error
> }
> }
> }
>
>> the standard route to the outer-class instance
>> would apply so it should just work, unless I'm missing something.
>
> That is what I would expect too but it doesn't happen (so we are both
> missing something)
>
>
In Java it's done this way:
class O
{
class I1
{
}
class I2
{
this()
{
I1 a = O.this.new I1;
}
}
}
"O.this" says "Give me the reference of O that contains me" and from
that point you say "new I1", that belongs to O. The syntax is a bit (a
lot?) strange, though...
However, if there is no ambiguity in "new I1", then writing "O.this" is
not necessary. So the example you sent works perfectly in Java, and I
think it should work the same way in D.
Ary
More information about the Digitalmars-d-learn
mailing list