class Base; class Lock { Lock() {} friend class Base; }; class Base : virtual private Lock { public: void foo() { std::cout << "Hello world" << std::endl; } }; class Derived : public Base { }; int main() { Derived obj; obj.foo(); return 0; } explain what the role of virtual is ... what if you inherit from the Lock class without virtual, then the code is compiled and gives an error
note: 'Derived :: Derived ()' is implicitly deleted: it would be ill-formed: class Derived: public Base