To trigger compiler errors, you can create both types as classes. In TypeA
make the conversion operator and / or constructor that will convert to / from TypeB
, and make these methods private .
Thus, any conversion from TypeB
to TypeA
will call the conversion function, and the compiler will throw an error that this method is private! Make sure that you may need to write several conversion operators / constructors from / in order for the conversion to succeed. I want to say that if you want to convert from float
, you need to write a constructor that accepts float
, etc. For other types.
You can write conversion operators, constructors in TypeA
or TypeB
and a list of valid conversions in these classes.
source share