Sobes.tech
Junior — Senior

Getting a pointer to the base class in protected inheritance

livecode

Task condition

Rewrite the given example without changing the access modifier protected to public. You need to show why attempting to create a derived object and assign it to a base class pointer results in a compilation error, and how to work around it without changing the access level.

class Base {
public:
    virtual ~Base() = default;
};

class Derived : protected Base {
};

void checkDerivedBase() {
    Base* basePtr = new Derived; // compilation error
}