I'm trying to create a type that can store either an int, a double, or an uint, like so:
struct Value
{
/*...*/
Value& operator=(const int value) { /*...*/ }
Value& operator=(const double value) { /*...*/ }
Value& operator=(const uint value) { /*...*/ }
operator int() const { /*...*/ }
operator double() const { /*...*/ }
operator uint() const { /*...*/ }
}
I got errors about "deduced conflicting types" when I'm trying to use it. I read somewhere that "deduction guide" can help but it seems to require template. My type doesn't need template.
Is there a solution to use this Value type without the need to cast it in int,double or uint everytime?
Value v;
v=123;
// I would like to type:
std::clamp(v,0,1234); // error
// But I need to type:
std::clamp(int(v),0,1234); // ok
I also have the same kind of problem with operator (with different error messages)
int x=v+12;
I think I should add more operator overloading, but I don't found which one.