virtual function call from base class

Posted by Gal Goldman on Stack Overflow See other posts from Stack Overflow or by Gal Goldman
Published on 2008-12-29T09:48:23Z Indexed on 2010/05/28 21:02 UTC
Read the original article Hit count: 251

Filed under:
|
|

Say we have:


Class Base
{   
    virtual void f(){g();};
    virtual void g(){//Do some Base related code;}
};

Class Derived : public Base
{   
    virtual void f(){Base::f();};
    virtual void g(){//Do some Derived related code};
};

int main()
{
    Base *pBase = new Derived;
    pBase->f();
    return 0;  
}

Which g() will be called from Base::f()? Base::g() or Derived::g()?

Thanks...

© Stack Overflow or respective owner

Related posts about c++

Related posts about polymorphism