How do you return a subclass instance from a base class method?

Daniel Daniel
Thu Nov 17 04:25:13 UTC 2022


I have SubclassOf derived from PosetRelation.  For any poset 
relation, the transitivity law applies, however, I'd like to 
return the correct type:

```
    PosetRelation transitivity(PosetRelation R, PosetRelation S)
    {
       if (R.op == S.op)
       {
          if (R.right is S.left)
             return new SubclassOf(R.left, S.right);
       }

       return null;
    }

```

How does one accomplish this in D?  Because PosetRelation doesn't 
know about SubclassOf, in general.


More information about the Digitalmars-d-learn mailing list