none
In C++ is it possible to call base class function from derived class object? RRS feed

  • Question

  • Hi,

    class Base
    
    {
    
    virtual func(char* buf, int l);
    
    };
    
    class Derived: public Base
    
    {
    
    virtual func(char* buf, int l);
    
    };
    
    class Ext: public Derived
    
    {
    
    bool b;
    
    void Call();
    
    };
    
    void Ext::Call()
    
    {
    
    if(b)
    
    {
    
    //call base class func
    
    }
    
    else
    
    {
    
    } //call derived class func
    
    }

    In the derived class of derived class based on some condition I have to call base class function or derived class function. Is it possible in C++?

    Thanks


    Tuesday, April 16, 2019 1:05 PM

Answers

  • Yes, you can explicitly choose the function to call, like this:

    Base::func(params);
    Derived::func(params);


    Igor Tandetnik

    • Marked as answer by sgrm123 Tuesday, April 16, 2019 1:42 PM
    Tuesday, April 16, 2019 1:35 PM