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.
Xmaki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6
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
1
You need to correct your code:
-
declare the class attribute int* intPtr = 0;
-
add the closing curly braces and the semicolon at the end of the class declaration.
After these modifications your code should compile.
Issa Taleb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3