Defining type coercion

Peter Lundgren lundgrpb at rose-hulman.edu
Sun Feb 27 12:10:43 PST 2011


I'd like to define a type Ordinal which behaves like an int (using a struct or
alias) that represents the 26 letters, A-Z, with the numbers 1-26. Then, I
would like to be able to coerce between chars and Ordinals appropriately.

chars and ints already have the ability to coerce between each other using the
appropriate ASCII values. So, really, I'd just like to define a type that
overrides this behavior.

As far as I can tell, the place to define such rules is with opCast!, but I'm
at a loss for how to add additional rules to built in types.


More information about the Digitalmars-d-learn mailing list