OK, I know that it’s impossible, but it was the best way to formulate the title of the question. The problem is, I’m trying to use my own custom class instead of float (for deterministic simulation) and I want to the syntax to be as close as possible. So, I certainly want to be able to write something like
FixedPoint myNumber = 0.5f;
Is it possible?
Yes, by creating an implicit type cast operator for
FixedPointif this class was written by you.If it’s not obvious to the reader/coder that a
doublecan be converted toFixedPoint, you may also use an explicit type cast instead. You then have to write: