The code below fails to compile.
if I remove the bool foo(bool) overload, then the a.foo(&b); call compiles.
if I remove the const qualifier from bool foo(bool*) const; then the a.foo(&b); call compiles.
While writing the question I found out that without -pedantic to gcc it also compiles
I can't understand why...
struct A {
bool foo(bool){
return true;
}
bool foo(bool*) const {
return false;
}
};
int main() {
A a;
a.foo(true);
bool b;
a.foo(b);
a.foo(&b); // does not compile
const_cast<const A&>(a).foo(&b); // does compile
}
and the compilation error:
error: call of overloaded ‘foo(bool*)’ is ambiguous
a.foo(&b);
^
/tmp/asdasd.cpp:4:8: note: candidate: bool A::foo(bool)
bool foo(bool){
^~~
/tmp/asdasd.cpp:7:8: note: candidate: bool A::foo(bool*) const
bool foo(bool*) const {
thanks