This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Override Private
- From: Liguo Song <Liguo dot Song at vanderbilt dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 29 May 2003 13:16:46 -0500
- Subject: Override Private
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.