Say I had a structure that represented a special numerical value, like a float with added functionality. This is just an example.
struct MyCustomFloat {
MyCustomFloat(float value);
MyCustomFloat(double value);
...
};
Then I had other functions that used instances of that struct. Another example.
MyCustomFloat add(MyCustomFloat x, MyCustomFloat y);
Is it possible to implement a way where I can give a int/float/double/etc. as my arguments for functions such as these and have them automatically converted to the custom type?
This way the messy code:
MyCustomFloat result = add(MyCustomFloat(1.5), MyCustomFloat(3.14));
Could be replaced with a cleaner:
MyCustomFloat result = add(1.5, 3.14);
And it would keep developers from having to write multiple versions of functions accepting each type of valid constructor input.
MyCustomFloat add(int x, int y);
MyCustomFloat add(float x, float y);
MyCustomFloat add(double x, double y);
MyCustomFloat add(int x, double y);
...