#include <iostream>
using namespace std;
struct Base
{
void foo() const {
cout << "Base::foo()\n";
}
virtual void virt() const {
cout << "Base::virt() called\n";
}
};
struct Derived : private Base
{
const Base* get() const {
return this;
}
private:
virtual void virt() const override {
cout << "Derived::virt() called\n";
}
};
int main()
{
Derived d;
//const Base *b = &d; //uncomment to get error
const Base *b = d.get();
b->foo();
b->virt();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEJhc2UKewogICAgdm9pZCBmb28oKSBjb25zdCB7CiAgICAgICAgY291dCA8PCAiQmFzZTo6Zm9vKClcbiI7CiAgICB9CiAgICAKICAgIHZpcnR1YWwgdm9pZCB2aXJ0KCkgY29uc3QgewogICAgICAgIGNvdXQgPDwgIkJhc2U6OnZpcnQoKSBjYWxsZWRcbiI7CiAgICB9Cn07CgpzdHJ1Y3QgRGVyaXZlZCA6IHByaXZhdGUgQmFzZQp7CiAgICBjb25zdCBCYXNlKiBnZXQoKSBjb25zdCB7CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICB9CiAgICAKcHJpdmF0ZToKICAgIHZpcnR1YWwgdm9pZCB2aXJ0KCkgY29uc3Qgb3ZlcnJpZGUgewogICAgICAgIGNvdXQgPDwgIkRlcml2ZWQ6OnZpcnQoKSBjYWxsZWRcbiI7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIERlcml2ZWQgZDsKICAgIC8vY29uc3QgQmFzZSAqYiA9ICZkOyAvL3VuY29tbWVudCB0byBnZXQgZXJyb3IKICAgIGNvbnN0IEJhc2UgKmIgPSBkLmdldCgpOwogICAgYi0+Zm9vKCk7CiAgICBiLT52aXJ0KCk7Cn0=