Lack of `outer` keyword makes inner class dup implossible

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Fri Jul 14 16:41:53 PDT 2006


Jarrett Billingsley wrote:
> "S." <S._member at pathlink.com> wrote in message 
> news:e98u9d$oqh$1 at digitaldaemon.com...
>> It seems that because inner classes lack an `outer` keyword it is 
>> impossible for
>> them to create a new instance for the purpose of COW when operators like 
>> opCom
>> are called...
> 
> It's irritating, isn't it?  The workaround is to make the ctor for the inner 
> class take a reference to its owning outer class, then you can use the 
> syntax
> 
> Inner dup()
> {
>     Inner n = outerThis.new Inner(outerThis);
>     return n;
> }
> 
> That is, you can 'new' the inner class using the outerThis reference.
> 
> I suppose another way would be to do some terribly ugly, nonportable hacks 
> to _find_ the outer pointer manually.  Maybe if we do that, Walter will see 
> that having an 'outer' reference would be useful.

Implementation of the inner class always stores the context pointer of
the outer class. It could be possible to instantiate yet another inner
class by implicitly providing the context pointer of the current outer
class to the new inner classes when 'new' is used without a prefix.
Again, that's how Java does it.

-- 
Jari-Matti



More information about the Digitalmars-d mailing list