Re: overload resolution before access checking
walter@digitalmars-nospamm.com (Walter Bright) wrote (abridged):
In other words, overload resolution happens before access checking. If
it happened after access checking, then S::foo(long) would have been
selected.
What is the rationale for this behavior
There is none.
In Stroustrup's D&E book he says he can't remember, but he thinks it just
fell out of the way the first parser was written without being consciously
chosen. It does mean that access control does not affect the semantics of
a program, only whether it compiles, but that wasn't the motivation for
it.
Shouldn't private members be invisible rather than inaccessible?
In any case, they are visible to the virtual dispatch mechanism.
#include "base.h"
class Derived : public Base {
private:
void dontCallMe() const;
};
Here Derived::dontCallMe() can in fact be called if the base class is
like:
class Base {
public:
virtual void dontCallMe() const;
}
The private Derived function overrides the public, virtual Base one even
though it is not itself declared virtual. This is one of the reasons
inheritance remains a dangerous, tightly-coupled relationship in C++.
-- Dave Harris, Nottingham, UK.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]