Function Overload

Q: What will happen when one try to compile the following code?

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 publics, protecteds, and privates 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.