Expression for: foo is derived from Clock
Nick Treleaven
nick at geany.org
Wed Feb 18 14:55:50 UTC 2026
On Wednesday, 18 February 2026 at 14:49:56 UTC, Brother Bill
wrote:
> ```Object foo``` is a class instance, perhaps null, perhaps a
> Clock or AlarmClock or Vegetable.
>
> What is the expression to ask the boolean question:
> Is foo of type Clock or a type derived from Clock, such as
> AlarmClock?
Use a cast:
https://dlang.org/spec/expression.html#cast_class
> I tried the obvious ```foo is Clock```, but this did not
> compile.
> ```
> Error: type `Object` is not an expression
> bool isClock = (o is Clock)
> ^
> ```
That use of `is` is a different expression:
https://dlang.org/spec/expression.html#identity_expressions
More information about the Digitalmars-d-learn
mailing list