Override Private
Liguo Song
Liguo.Song@vanderbilt.edu
Thu May 29 19:26:00 GMT 2003
I saw a trick to overrides the member function's private specification. It is as
following:
class Base {
private:
virtual void fun(){ cout << "Base" << endl;};
};
class Derived:private Base {
public:
void fun() { cout << "Derived" << endl;};
};
int main() {
Derived* bp = (Derived *) new Base;
bp->fun();
return 0;
}
And, this will give "Base" as the Base::fun() is run.
Is this an intentional behavior or just the compiler gets confused here?
If it is intentional, any justification for this?
Thanks for your comments.
More information about the Gcc-help
mailing list