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

Daniel Daniel
Thu Nov 17 05:22:02 UTC 2022


```
PosetRelation transitivity(PosetRelation R, PosetRelation S)
{
    // These if conditions are typically ordered from easiest to
    // most involved-to-check.
    if (R.op == S.op &&
        is(typeof(R) == typeof(S)) &&
        R.right == S.left)
    {
       return new typeof(R)(
          R.left, S.right,
          by("transitivity of " ~ R.op));     // Proof by this 
axiom
    }

    return null;
}
```

Not sure if that would work yet.  Have to test it.


More information about the Digitalmars-d-learn mailing list