#include <iostream>usingnamespacestd;classA{public:// NOTE: Here bar() is publicvirtualstringbar(){return"A::bar";}};classB:publicA{private:// NOTE: Here bar() is privatevirtualstringbar(){return"B::bar";}};voidfoo(A*a){cout<<a->bar()<<endl;}intmain(){B*b=newB();// We pass a B object to the foo function for which the bar method is// private and so should not be possible to call it from outside the class...// Anyway the bar() method will be called successfully returning "B::bar"foo(b);}