Simulating sub types

JS js.mdnq at gmail.com
Fri Aug 2 06:37:08 PDT 2013


On Friday, 2 August 2013 at 12:29:02 UTC, Meta wrote:
> On Friday, 2 August 2013 at 11:47:46 UTC, bearophile wrote:
>> JS:
>>
>>> the fact remains that I can't do it in Dlang.
>>
>> Is tagging the inner class as static helping?
>>
>> class A {
>>    static class B { ... }
>> }
>>
>> Bye,
>> bearophile
>
> Just to be clear, marking the inner class as static means that 
> B will not have a pointer to A. It is the same as defining B 
> outside A, the difference being that B is not visible to 
> anything outside the module.

Then that doesn't help. Do you mean A.B is not visible outside 
the module either? Can B be instantiated and inherited when 
static, if not then it is no use.

To be. clear I want B to behave like any ordinary "root" 
class(just like A), except I want to have to access it through 
A(logically). This creates a hierarchical way of accessing types 
that makes it clear how they are related to other types, but 
doesn't prevent them from being used in a non-hierarchical way if 
necessary(The way D deals with nested classes prevents this).



More information about the Digitalmars-d-learn mailing list