Re: Restricting access should be illegal?
Walter Bright wrote:
Consider the following legal code:
-----------------------
#include <stdio.h>
class A {
public:
virtual void Member() { printf("A::Member\n"); }
};
class B : public A {
private:
virtual void Member() { printf("B::Member\n"); }
};
int main()
{
B *b = new B();
// b->Member(); // error, B::Member is private
A *a = b;
a->Member(); // calls B::Member
}
-------------------------
Shouldn't restricting access to an overriding virtual function
be an error? After all, we can get at it anyway via an
implicit conversion. Does anyone know of a legitimate design
pattern that does this?
I can't think of any real use for it, but banning it introduces
a special rule, and IMHO isn't worth it.
--
James Kanze kanze.james@neuf.fr
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]