logo       

Override Private: msg#00276

gcc.help

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.




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise