Reputation: 603
Is it somehow possible to call a default function each time an overloaded operator is called?
E.g., you have a class which contains a value either in meters or yards and you want to check both of them to have equal units before applying the overloaded operator. Right now I'm using a checkCompatibility()
-function in every overloaded operator definition, but it would be convenient if that would happen automatically for any overloaded binary operation.
Upvotes: 1
Views: 248
Reputation: 76778
There is no such functionality, but Boost.Units is designed to solve problems with unit conversion (at compile time). Your function would take a quantity<length>
as parameter, and the library makes sure anything that is passed in is compatible and handles the conversion of units.
Upvotes: 1