The code: has made calls to private member via object pointer
#include <iostream>
using std::cout;
using std::endl;
class A
{
public:
virtual void foo1(){cout<<"A::foo1()"<<endl;}
private:
virtual void foo(){cout<<"A::foo()"<<endl;}
};
class B:private A
{
private:
virtual void foo1(){cout<<"B::foo1()"<<endl;}
public:
virtual void foo(){cout<<"B::foo()"<<endl;}
};
int main()
{
B b;
A *a=(A *)&b;
a->foo1();
A a1;
B *b1=(B *)&a1;
b1->foo();
return 0;
}
/*
The code above makes calls to private member via object pointer, pls explain why.
This question is mentioned first in the following link, thank the original initiator.
http://expert.csdn.net/Expert/topic/1307/1307940.xml?temp=.5337946
*/