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]

Private virtual function overridden as public compiles and runs (bug?)


The following program compiles and runs - is it correct behavior? I
read §11.5 in the January 2012 working draft but couldn't reach a
conclusion.

class B
{
    virtual int f() { return 42; };
};

class D : public B
{
public:
    int f() { return 43; };
};

int main()
{
    D d;
    B * pb = &d;
    D * pd = &d;
    //pb->f(); // error: B::f() is private
    pd->f(); // OK: D::f() is public
}

Georger


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