#include #include using namespace std; class base { protected: void f() const {cout << "base::f\n";} }; class derived1: public base { }; class derived2: public base { public: void g() const { f(); //will compile derived2 d2; d2.f(); //will compile derived1 d1; //d1.f(); //won't compile base b; //b.f(); //won't compile //static_cast(this)->f(); //won't compile } }; int main() { derived2 d2; d2.g(); return EXIT_SUCCESS; }