#include<iostream>classBase{public:intm_value{};};classDerived:publicBase{private:usingBase::m_value;public:Derived(intvalue)// We can't initialize m_value, since it's a Base member (Base must initialize it){// But we can assign it a valuem_value=value;}};intmain(){Derivedderived{7};// The following won't work because m_value has been redefined as privatestd::cout<<derived.m_value;return0;}
#include<iostream>classBase{private:intm_value{};public:Base(intvalue):m_value{value}{}intgetValue()const{returnm_value;}};classDerived:publicBase{public:Derived(intvalue):Base{value}{}intgetValue()=delete;// mark this function as inaccessible};intmain(){Derivedderived{7};// The following won't work because getValue() has been deleted!std::cout<<derived.getValue();return0;}