X-Maki
X-Maki

Reputation: 41

Overloaded functions have similar conversions

My program will not compile, and give the error overloaded functions have similar conversions. What does this mean and how do I fix it?

struct DynamicInt {
    bool operator==(const DynamicInt&);
};

int main()
{
    DynamicInt a, b;
    return a == b;      // error at this line
}

Demo.

Upvotes: 0

Views: 295

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38863

Just follow the hints in the compiler warnings:

note: mark 'operator==' as const or add a matching 'operator!=' to resolve the ambiguity

and change

bool operator==(const DynamicInt& operand2) const {
                                            ^^^^^

and you get it compiled, https://godbolt.org/z/7vdxjEEv4

Upvotes: 3

Related Questions