class Test {
public:
void Foo(int x) {}
private:
void Foo(float x) {}
};
int main() {
Test t;
t.Foo(1);
t.Foo(1.0);
}
A: The code will fail to compile saying that your compiler cannot resolve ambigous overload of
Foo
. That happens so, because C++ performs overload resolution before accessibility checking. I.e. it ignores all public
s, protected
s, and private
s when it looks for a better match. The trick here is that newbies will usually answer that the 2nd call to Foo
will truncate double 1.0
to integer 1
, which is not true.