Coderiving

JohnC johnch_atms at hotmail.com
Tue Nov 21 09:32:17 PST 2006


"Karen Lanrap" <karen at digitaldaemon.com> wrote in message 
news:Xns9882A8C0ABB63digitaldaemoncom at 63.105.9.61...
> Why one can derive from a nested class only in the corresponding
> super class?
>
> The example gives the error:
>> super class Id is nested within Concept, not Concrete
>
> But Concrete is derived from Concept and should contain the
> definition of the class Id!
>
>
> <code>
> interface Identifier
> {
>    char[] whoAmI();
> }
> class Concept
> {
>    class Id:Identifier
>    {
>        char[] whoAmI()
>        {
>            return "Concept.".dup;
>        }
>    }
> }
>
> class Concrete: Concept
> {
>    class Idl: Id  //does not work
>    {
>        char[] whoAmI(){
>            return "Concrete.".dup;
>        }
>    }
> }
> void main()
> {
>    auto instance= new Concrete;
> }
> </code>
>

To make it work, declare Id and Idl with the static attribute.

class Concept {
  static class Id : Identifier { ... }
}

class Concrete : Concept {
  static class Idl : Id { ... }
} 





More information about the Digitalmars-d-learn mailing list