Default overloaded operator in ambiguous case [closed]

  ambiguous, c++, operator-overloading

I keep hitting an error that a I have a ambiguous piece of code in my class. I also want my code to be able to return a size_t variable when a int or size_t variables.
Here is a example:

class c {
    public: 
        int operator*(size_t a) {
            return static_cast<int>(a);
        }

        int operator*(double a) {
            return static_cast<int>(a)
        }
};
int main(void) {
    c x {};
    do_something(c + 2);
}

Here, 2 both corresponds with size_t and double, so I get an ambiguous call. Is there a way to make these int types correspond to the size_t overload?

Source: Windows Questions C++

LEAVE A COMMENT