Consider this code:
struct A
{
void foo() const
{
std::cout << \"const\" << std::endl;
}
private:
void foo()
Ultimately this comes down to the assertion in the standard that accessibility should not be taken into consideration when performing overload resolution. This assertion may be found in [over.match] clause 3:
... When overload resolution succeeds, and the best viable function is not accessible (Clause [class.access]) in the context in which it is used, the program is ill-formed.
and also the Note in clause 1 of the same section:
[ Note: The function selected by overload resolution is not guaranteed to be appropriate for the context. Other restrictions, such as the accessibility of the function, can make its use in the calling context ill-formed. — end note ]
As for why, I can think of a couple of possible motivations: