This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]