#include <iostream>
class Base {
protected:
int x;
void pfunction() { std::cout << "Access to pfunction() OK\n"; }
public:
void setx( int i ) { x = i; }
void Display() { std::cout << x << "\n"; }
} cb;
class Derived : public Base {
public:
void f() { pfunction(); }
} dc;
int main() {
// cb.x; // error: ‘int Base::x’ is protected within this context
cb.setx(298);
cb.Display();
dc.setx(3);
dc.Display();
// cb.pfunction(); // error: ‘void Base::pfunction()’ is protected within this context
dc.f();
return 0;
}
/*
run:
298
3
Access to pfunction() OK
*/