0

Consider the following code:

#include <iostream>

using namespace std;

class Parent{
    virtual void print() = 0;
};

class Derived : public Parent {};

int main() {
    Derived d1;
    return 0;
}

My doubt over here is that, print function in the parent class is a private member function, then how does it get inherited in the derived class?

2
  • Virtual methods can be overriden, even if they are private. Its just is as it is.
    – freakish
    Apr 14, 2021 at 17:22
  • 2
    That capability in C++ is used as part of the non-virtual interface pattern.
    – Eljay
    Apr 14, 2021 at 17:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.