#include <iostream>
#include <cstddef>
class Base
{
public :
virtual void foo( ) { std:: cout << __PRETTY_FUNCTION__ << std:: endl ; }
} ;
class Derived1 : public Base
{
private :
virtual void foo( ) { std:: cout << __PRETTY_FUNCTION__ << std:: endl ; }
} ;
class Derived2 : public Derived1
{
public :
virtual void foo( ) { std:: cout << __PRETTY_FUNCTION__ << std:: endl ; }
} ;
int main( int argc, char ** argv)
{
Base* derived1 = new Derived1( ) ;
std:: cout << "Overriden methods from public inheritance cannot be forced to be private" << std:: endl ;
derived1- > foo( ) ;
Base* derived2 = new Derived2( ) ;
std:: cout << "False attempt to make ::foo private in Derived1 doesn't work, Derived2 can still override it." << std:: endl ;
derived2- > foo( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGRlZj4KCmNsYXNzIEJhc2UKewogIHB1YmxpYzoKICAgIHZpcnR1YWwgdm9pZCBmb28oKSB7IHN0ZDo6Y291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKY2xhc3MgRGVyaXZlZDEgOiBwdWJsaWMgQmFzZQp7CiAgcHJpdmF0ZToKICAgIHZpcnR1YWwgdm9pZCBmb28oKSB7IHN0ZDo6Y291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKY2xhc3MgRGVyaXZlZDIgOiBwdWJsaWMgRGVyaXZlZDEKewogIHB1YmxpYzoKICAgIHZpcnR1YWwgdm9pZCBmb28oKSB7IHN0ZDo6Y291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIqKiBhcmd2KQp7CgogIEJhc2UqIGRlcml2ZWQxID0gbmV3IERlcml2ZWQxKCk7CiAgc3RkOjpjb3V0PDwgIk92ZXJyaWRlbiBtZXRob2RzIGZyb20gcHVibGljIGlua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