0

https://www.geeksforgeeks.org/polymorphism-in-c/

In function overriding in c++, how can I print the base class non-virtual member function from the derived class function using the derived class obj

  • 1
    Possible duplicate of [Can I call a base class's virtual function if I'm overriding it?](https://stackoverflow.com/questions/672373/can-i-call-a-base-classs-virtual-function-if-im-overriding-it) – Fureeish Jul 19 '18 at 10:22

1 Answers1

2

You can always call the base class function from derived class. For example:

class parent
{
public:
    virtual void print()
    {
        std::cout << "base class" << std::endl;
    }
};

class child: parent
{
public:
    void print()
    {
        parent::print();
        std::cout << "child class" << std::endl;
    }
};
int main(int argc, char *argv[])
{
    child c;
    c.print();
    return 0;
}
PVRT
  • 480
  • 4
  • 13